Exception:
//throws出现在方法声明,而throw出现在可执行代码中。
如: 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时要导入:
import java.io.IOException;
import java.awt.AWTException;
import java.sql.SQLException;
//throws出现在方法声明,而throw出现在可执行代码中。
如: 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时要导入:
import java.io.IOException;
import java.awt.AWTException;
import java.sql.SQLException;