Tuesday, 20 August 2013

Exception not thrown Java

Exception not thrown Java

class ex1
{
static void my() {
System.out.println("asdsdf");
}
public static void main(String args[]) {
try {
for (;;) {
my();
}
} catch (Exception e)//Exception is not caught //Line 1
{
System.out.println("Overflow caught");
} finally {
System.out.println("In Finally");
}
System.out.println("After Try Catch Finally...");
}
}
The catch statement (Line 1) does not handle the overflow exception as
such the output keeps on printing "asdsdf" without throwing an exception.
Can anyone tell me why an infinite loop is not handled as an exception ?.
Or that's the way it's designed and supposed to work ?

No comments:

Post a Comment