Exception:
throws出现在方法声明,而throw出现在可执行代码中。
如:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| public float getrain(float a) throws Exception { if(a < 0) { Exception x = new Exception("the db must be wrong!"); throw x; } else return 0; }
try{ .................... } catch(Exception x) { ................ }
|
使用IOException,SQLException,AWTEception时要导入:
1 2 3 4
| import java.io.IOException; import java.awt.AWTException; import java.sql.SQLException;
|