vysh
05-29-2009, 07:18 AM
Hi all,
I have the following code block:
class exceptiondemo
{
static void test() throws Error
{
if (true)
throw new AssertionError();
System.out.print("test ");
}
public static void main(String[] args)
{
try
{
test();
}
catch (Exception ex)
{
System.out.print("exception ");
}
finally
{
}
System.out.print("end ");
}
}
Here a throwable is thrown by main, because the AssertionError is not caught. If the catch block would have been, catch(AssertionError ex), then the exception would have been caught. But I have used finally block. Can't the finally block catch this error?
I have the following code block:
class exceptiondemo
{
static void test() throws Error
{
if (true)
throw new AssertionError();
System.out.print("test ");
}
public static void main(String[] args)
{
try
{
test();
}
catch (Exception ex)
{
System.out.print("exception ");
}
finally
{
}
System.out.print("end ");
}
}
Here a throwable is thrown by main, because the AssertionError is not caught. If the catch block would have been, catch(AssertionError ex), then the exception would have been caught. But I have used finally block. Can't the finally block catch this error?