关于强制转换的一个问题?
public class app
{
public static void aaa(int a,int b) throws Exception
{
double c=(double)a/b;
System.out.println(a+"/"+b+"="+c);
}
public static void main(String args[])
{
try
{
aaa(4,0);
}
catch(Exception e)
{
System.out.println(e+"exception");
}
finally
{
try
{aaa(4,5);}
catch(Exception e)
{System.out.println("sdjfas;f");}
}
System.out.println("The main method is end");
}
}
如上面一个程序,如果我在aaa中:double c=(double)a/b;
则不会抛出异常,结果显示为:
4/0=Infnity
4/5=0.8 ……
但是如果是:int c=a/b;
则会抛出异常,请问这是什么原因啊?