javaにおける異常な処理

547 ワード

throwsキーワード声明は、throws声明を使用する方法は、この方法が異常を処理するのではなく、方法の呼び出し先に処理されることを示しています。
   throwのキーワードは人为的に一つの异常を投げて、异常を投げた时、直接に例外类の実例化対象を投げたらいいです。
class Math
{
public int div(int i,int j) throws Exception
{
try{
int temp=i/j;
return temp;
}catch(Exception e)
{
throw e;
}
retrun temp;
}
}

public class ThrowsDemo1
{
public static void main(String arg[])
{
Math m=new Math();
try
{
System.out.println("    :"+m.div(10,2));
}catch(Exception e)
{
e.printStackTrace();
}
}
}
try…catch;異常な処理を行うことです。
throwとthrows:例外的に投げるだけです。