两种表示异常类的方法
2017-05-16 17:25
225 查看
1 用 try-catch的方法。。
2 自定义异常类
要注意如果错误就抛出。然后在catch里处理
package why; import java.util.*; public class iiii { public static void main(String args[]) { int n=0,m=0,t=0; try { t=9999; m=Integer.parseInt("8888"); n=Integer.parseInt("13a"); System.out.println("我没有机会输出"); } catch(Exception e) { System.out.println("eror"); System.out.println(m); } } }
2 自定义异常类
要注意如果错误就抛出。然后在catch里处理
package why; import java.util.*; class Myexception extends Exception { String message; Myexception (int n) { message=n+"不是正数"; } public String getMessage() { return message; } } public class lovestick { public static void main(String args[]) { try { int m=2; int s=-1; if(s<0) { Myexception xx=new Myexception(s); throw(xx); } } catch(Myexception xx) { System.out.println(xx.getMessage()); } } }
相关文章推荐
- 关系有两种表示方法
- 在Linux系统中存储设备的两种表示方法
- 在Linux系统中存储设备的两种表示方法-sdxx和(hdx,x)
- 程序员面试100题(算法)之整数的二进制表示中1的个数(两种方法)
- 在Linux系统中存储设备的两种表示方法
- path的两种表示方法"/"和"//"。
- 处理数组的函数,我们有两种表示方法
- 在Linux系统中存储设备的两种表示方法
- 在Linux系统中存储设备的两种表示方法
- Excel是最常用的办公软件。每个单元格都有唯一的地址表示。 比如:第4列表示为:“D”,第255列表示为“IU”。 事实上,Excel提供了两种地址表示方法,还有一种表示法叫做RC格式地址。
- 在Linux系统中存储设备的两种表示方法
- 在Linux系统中存储设备的两种表示方法
- 在Linux系统中存储设备的两种表示方法
- 策略模式的两种表示方法
- 在Linux系统中存储设备的两种表示方法
- 文件系统管理 之 在Linux系统中存储设备的两种表示方法
- 比较两种异常捕获的方法
- 在Linux系统中存储设备的两种表示方法
- 在Linux系统中存储设备的两种表示方法
- (方法二)Excel是最常用的办公软件。每个单元格都有唯一的地址表示 比如:第4列表示为:“D”,第255列表示为“IU”。 事实上,Excel提供了两种地址表示方法,还有一种表示法叫做R