抛出异常:
throw:手动抛出异常
声明异常:
thorws:声明方法可能要抛出的各种异常
package cn.zzx.insert;
public class LostMessage {
void w() throws Normal{
throw new Normal();
}
void dispose() throws Exception{
throw new ImportantException();
}
public static void main(String[] args) throws Exception {
LostMessage a = new LostMessage();
try {
a.w();
} catch (Normal e) {
System.out.println(e.getMessage());
e.printStackTrace();
}try{
a.dispose();
}
catch(ImportantException e){
System.out.println(e.getMessage());
e.printStackTrace();
}
}
}