import java.io.*;
class MyException extends Exception
{
MyException()
{
super();
}
MyException(String s)
{
super(s);
System.out.println("the Exception with ABCD");
}
}
public class exception2
{
public static void main(String args[])throws IOException
{
while(true)
{
try
{
fn();
}
catch(RuntimeException e)
{
try
{
throw e.getCause();//这个方法不对么
}
catch(IOException s)
{
System.out.println("please again");
}
catch(MyException m)
{
break;
}
}
}
}
static void fn()
{
try
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("putout u String");
String temp=br.readLine();
if(temp.equals("ABCD")==false)
{
throw new IOException();
}
else if(temp.equals("ABCD")==true)
{
throw new MyException("ABCD");
}
}catch(Exception e)//把他包装成runtime的异常
{
throw new RuntimeException(e);
}
}
}
怎么解决,让异常正确识别其类型????