- public class Throws_与Throw处理异常 {
- public static void main(String[] args) {
- System.out.println("少壮不努力");
- try {
- method();
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- //method2();
- System.out.println("老大徒伤悲");
- }
- /* public static void method2() {
- // TODO Auto-generated method stub
- int a = 10;
- int b = 0;
- if (b==0) {
- throw new ArithmeticException();
- }else{
- System.out.println(a/b);
- }
-
- }*/
- public static void method() throws Exception {
- // TODO Auto-generated method stub
- int a = 10;
- int b = 0;
- if (b==0) {
- throw new Exception();
- }else{
- System.out.println(a/b);
- }
- }
- }
复制代码 |
|