如下面的代码,结果就不解释了。
- public class TryTest
- {
- public static void main(String[] args)
- {
- TryTest tt = new TryTest();
- tt.test1();
- System.out.println();
- tt.test2();
- System.out.println();
- tt.test3();
- }
- public void test1()
- {
- int a = 2;
- System.out.println("start");
- try
- {
- a = a/0;
- }catch(Exception e)
- {
- System.out.println("catch");
- }finally
- {
- System.out.println("finally");
- }
- System.out.println("end");
- }
- public void test2()
- {
- int a = 2;
- System.out.println("start");
- try
- {
- a = a/0;
- }catch(Exception e)
- {
- System.out.println("catch");
- return;
- }finally
- {
- System.out.println("finally");
- }
- System.out.println("end");
- }
- public void test3()
- {
- int a = 2;
- System.out.println("start");
- try
- {
- a = a/0;
- }catch(Exception e)
- {
- System.out.println("catch");
- System.exit(0);
- }finally
- {
- System.out.println("finally");
- }
- System.out.println("end");
- }
- public void test()
- {
- //只有final可以使用
- final int a = 1;
- // static int b = 2;
- // final static int c = 3;
- // private int d = 4;
- }
- }
public class TryTest
{
public static void main(String[] args)
{
TryTest tt = new TryTest();
tt.test1();
System.out.println();
tt.test2();
System.out.println();
tt.test3();
}
public void test1()
{
int a = 2;
System.out.println("start");
try
{
a = a/0;
}catch(Exception e)
{
System.out.println("catch");
}finally
{
System.out.println("finally");
}
System.out.println("end");
}
public void test2()
{
int a = 2;
System.out.println("start");
try
{
a = a/0;
}catch(Exception e)
{
System.out.println("catch");
return;
}finally
{
System.out.println("finally");
}
System.out.println("end");
}
public void test3()
{
int a = 2;
System.out.println("start");
try
{
a = a/0;
}catch(Exception e)
{
System.out.println("catch");
System.exit(0);
}finally
{
System.out.println("finally");
}
System.out.println("end");
}
public void test()
{
//只有final可以使用
final int a = 1;
// static int b = 2;
// final static int c = 3;
// private int d = 4;
}
}
输出为:
- start
- catch
- finally
- end
- start
- catch
- finally
- start
- catch
- 我的异常网
Java Exception
Dotnet Exception
Oracle Exception