异常
来源:互联网 发布:甬航数据交互平台 编辑:程序博客网 时间:2024/06/04 17:44
package class1;
class Math {
public int div(int i ,int j) throws Exception {
System.out.println("====计算开始=====");
int temp = 0 ;
try {
temp = i / j ;
} catch (Exception e ) {
throw e ;
} finally {
System.out.println(" ======计算结束====");
}
return temp ;
}
}
public class ThrowDemo02 {
public static void main(String args[]) {
Math m = new Math() ;
try {
System.out.println("除法操作:" + m.div(10, 0));
} catch (Exception e) {
System.out.println("异常产生:" + e);
}
}
}
//throw抛出一个异常对象
//throws向上抛(Exception,Error)
//尽量使用try-catch
class Math {
public int div(int i ,int j) throws Exception {
System.out.println("====计算开始=====");
int temp = 0 ;
try {
temp = i / j ;
} catch (Exception e ) {
throw e ;
} finally {
System.out.println(" ======计算结束====");
}
return temp ;
}
}
public class ThrowDemo02 {
public static void main(String args[]) {
Math m = new Math() ;
try {
System.out.println("除法操作:" + m.div(10, 0));
} catch (Exception e) {
System.out.println("异常产生:" + e);
}
}
}
//throw抛出一个异常对象
//throws向上抛(Exception,Error)
//尽量使用try-catch
阅读全文
0 0
- 异常
- 异常!
- 异常
- 异常
- 异常
- 异常
- 异常
- 异常
- 异常
- 异常
- 异常
- 异常
- 异常
- 异常
- 异常
- 异常
- 异常
- 异常
- IP问问区县级别IP地址库---使用帮助(下篇)
- 解决easyui和bootstrap兼容问题
- Spring 整合 spark 使用
- java基本数据类型
- 腾讯2017暑期实习生编程题
- 异常
- js再次确认密码
- 注释
- Windows 更新安装 Windows 7 SP1失败错误代码80073712解决方法:
- FP-growth算法发现频繁项集(一)——构建FP树
- Python 中 变量的 is 和 == 符号的作用
- codeforces 603E(LCT+优先队列)
- 链表的常见操作入门(一)
- Codeforces Round #433 (Div. 1, based on Olympiad of Metropolises) C. Boredom(主席树)