public class Test
{
public static void main(String[] args)
{
Test t = new Test();
t.show();
}
public void show()
{
int a = 0;
while(true)
{
try
{
if(a++ == 0)
throw new MyException();
System.out.println("No Exception");
}catch(MyException e)
{
System.out.println("MyException");
}catch(Exception e)
{
System.out.println("Exception");
}finally
{
System.out.println("Finally");
if(a == 2)
break;
}
}
}
}
class MyException extends Throwable
{
private static final long serialVersionUID = -2022776205202627089L;
}
输出为:
MyException
Finally
No Exception
Finally
{
public static void main(String[] args)
{
Test t = new Test();
t.show();
}
public void show()
{
int a = 0;
while(true)
{
try
{
if(a++ == 0)
throw new MyException();
System.out.println("No Exception");
}catch(MyException e)
{
System.out.println("MyException");
}catch(Exception e)
{
System.out.println("Exception");
}finally
{
System.out.println("Finally");
if(a == 2)
break;
}
}
}
}
class MyException extends Throwable
{
private static final long serialVersionUID = -2022776205202627089L;
}
输出为:
MyException
Finally
No Exception
Finally