<span style="font-size:12px;">
class Test {
public int devide(int x,int y) throws Exception //<span style="color:#FF0000;">throws exception标示:声明该函数有可能发生异常</span>
{
if(y<0)
throw new DevideByMinusException("devisor is"+y);
int result = x/y;
return result;
}
}
/*class SubTest extends Test
{
public int devide(int x,int y)
}
*/
class DevideByMinusException extends Exception
{
public DevideByMinusException(String msg)
{
super(msg);
}
}
class TestException
{
public static void main (String [] args) throws Exception
{
try
{
new Test().devide(3,0);
}
catch (Exception ex)
{
// TODO: handle exception
System.out.println(ex.getMessage());
}
System.out.println("prograss");
}
}
</span>
Java 异常
最新推荐文章于 2024-03-09 14:23:12 发布