import java.io.*;
class MyException extends Exception{
private String reason;
public MyException(String r){
reason=r;
}
public String getReason(){
return(reason);
}
}
class Excp{
private String s;
public Excp(String ss)throws MyException{
s=ss;
if(s=="XYZ"){
throw new MyException("This is a XYZ");
}
}
}
class Test_Excp{
public static void main(String args[])throws Exception{
byte buffer[]=new byte[255];
System.out.println("Plz input s1:");
System.in.read(buffer,0,255);
String s1=new String(buffer);
try{
Excp e1=new Excp(s1);
}
catch(MyException e){
System.out.println("ddfd");
}
}
}
class MyException extends Exception{
private String reason;
public MyException(String r){
reason=r;
}
public String getReason(){
return(reason);
}
}
class Excp{
private String s;
public Excp(String ss)throws MyException{
s=ss;
if(s=="XYZ"){
throw new MyException("This is a XYZ");
}
}
}
class Test_Excp{
public static void main(String args[])throws Exception{
byte buffer[]=new byte[255];
System.out.println("Plz input s1:");
System.in.read(buffer,0,255);
String s1=new String(buffer);
try{
Excp e1=new Excp(s1);
}
catch(MyException e){
System.out.println("ddfd");
}
}
}
换成"XYZ".equals(s)
import java.io.*;class MyException extends Exception {
private String reason; public MyException(String r) {
reason = r;
} public String getReason() {
return (reason);
}
}class Excp {
private String s; public Excp(String ss) throws MyException {
s = ss;
if (s.equals("XYZ")) {
throw new MyException("This is a XYZ");
}
}
}public class Test_Excp {
public static void main(String args[]) throws Exception {
System.out.println("Plz input s1:");
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String s1 = in.readLine();
try {
Excp e1 = new Excp(s1);
} catch (MyException e) {
System.out.println("ddfd");
}
}
}
.....
System.in.read(buffer,0,255);
String s1=new String(buffer).trim(); //那个Buffer含有无效的字符
.................