try {
// Code that might generate exceptions
-
} catch(Type1 id1) {
// Handle exceptions of Type1 -
} catch(Type2 id2) {
// Handle exceptions of Type2 -
} catch(Type3 id3) {
// Handle exceptions of Type3} finally {
// 每次都会发生的情况
}throws;后面跟随全部潜在的违例类型。方法定义可能抛出的异常:
void f() throws tooBig, tooSmall, divZero { //...
抛出异常 throw:
catch(Exception e) {
System.out.println("一个违例已经产生");throw e;
}