这是关于抛出异常的在线教程
我正在尝试做这样的事情:
int power(int n, int p){
try
{
return (int)Math.pow(n,p);
}
catch(Exception e)
{
throw new Exception("n and p should be non-negative");
}
}
Run Code Online (Sandbox Code Playgroud)
但我得到了错误
错误:未报告的异常Exception;必须被抓住或宣布被扔出