package com.text.exception;
class Test{
void add(int a,int b) throws Exception
{
int c;
c=a/b;
System.out.println(a+"/"+b+"="+c);
}
}
class DefaultException extends Exception
{
public DefaultException(String msg){
//调用Exception类的构造方法,存入异常信息
super(msg);
}
}
public class TestException {
/* static void add(int a,int b) throws Exception
{
int c;
c=a/b;
System.out.println(a+"/"+b+"="+c);
}
*/
public TestException() {
// TODO Auto-generated constructor stub
}
/**
* @param args
*/
public static void main(String[] args){
// TODO Auto-generated method stub
//add(4,0);
try{
throw new DefaultException("自定义异常!");
}
catch(Exception e){
System.out.println(e);
}
/* Test t = new Test();
try{
t.add(5, 0);
}
catch(Exception e){
System.out.println("异常:"+e);
} */
// int arr[] = new int[5];
// try{
// arr[6] = 10;
// }
// catch(Exception e){
/* catch(ArrayIndexOutOfBoundsException e){
System.out.println(e.getMessage().toString());
System.out.println("异常:"+e);
System.out.println(e.getLocalizedMessage());
}
*/
System.out.println("end of main() method!");
}
}