异常
异常分类
try catch
package com.jxd;
public class Test
{
public static void main(String args[])
{
System.out.println("111111111");
try
{
System.out.println("try 1");
int value = 1/0;
System.out.println("try 2");
}
catch(Exception e)
{
System.out.printlpackage com.jxd;
public class Test
{
public static void main(String args[])
{
System.out.println("111111111");
try
{
System.out.println("try 1");
int value = 1/0;
System.out.println("try 2");
}
catch(Exception e)
{
// 异常均会进入
System.out.println("Exception 1");
e.printStackTrace();
System.out.println("Exception 2");
}
finally
{
// 是否异常均会进入finally
System.out.println("finally");
}
System.out.println("222222222");
}
}
结果:
已连接到目标 VM, 地址: ''127.0.0.1:54715',传输: '套接字''
111111111
try 1
Exception 1
Exception 2
finally
222222222
java.lang.ArithmeticException: / by zero
at com.jxd.Test.main(Test.java:13)
与目标 VM 断开连接, 地址为: ''127.0.0.1:54715',传输: '套接字''
进程已结束,退出代码0
关注
笔者 - jxd
微信公众号搜索 “码农总动员” 或 微信扫描下方二维码,了解更多你不知道的XX,O(∩_∩)O