- class Demo
- {
- int div(int a,int b) throws Exception
- {
- return a/b;
- }
- }
- class Demo4
- {
- public static void main(String[] args)
- {
- Demo d=new Demo();
- try
- {
- int x=d.div(4,0);
- System.out.println("x="+x);
- }
- catch (Exception e)
- {
- System.out.println("除以零了");
- //System.out.println(e.getMessage());
- System.out.println(e.toString());
- //e.printStackTrace();
- }
-
- System.out.println("over");
- }
- }
复制代码
|
|