1-Error v/s Exception
java.lang.Throwable is the super class of the java.lang.Error and java.lang.Exception
Error which is mainly caused by the environment in which application is running
Error is mostly occur at runtime
All Error is unchecked type of Exception
1-stackOverflowError
2-OutOfMemory
Exception is mainly caused by application itself
1-NullPointer
2-FileNotFound
3-IO
4-ArrayOutOfBound
5-NumberFormatException
Recovery from the error is not possible only solution is to terminate the program
Exception can be handled using try and catch block
Exception is of two types
1-CheckedException - must be cached and handled at Runtime
2-UncheckedException
2-Can we write any statement between try and catch block
No it will sue you
3) There are three statements in a try block – statement1, statement2 and statement3. After that there is a catch block to catch the exceptions occurred in the try block. Assume that exception has occurred in statement2. Does statement3 get executed or not?
No statement3 will never executed in this case
4)What is unreachable catch block error?
try
{
int i = Integer.parseInt("abc"); //This statement throws NumberFormatException
}
catch(Exception ex)
{
System.out.println("This block handles all exception types");
}
catch(NumberFormatException ex)
{
//Compile time error
//This block becomes unreachable as
//exception is already caught by above catch block
}
5) What is Re-throwing an exception in java?
if you throw any exception in the catch block, its called re-throwing the exception
java.lang.Throwable is the super class of the java.lang.Error and java.lang.Exception
Error which is mainly caused by the environment in which application is running
Error is mostly occur at runtime
All Error is unchecked type of Exception
1-stackOverflowError
2-OutOfMemory
Exception is mainly caused by application itself
1-NullPointer
2-FileNotFound
3-IO
4-ArrayOutOfBound
5-NumberFormatException
Recovery from the error is not possible only solution is to terminate the program
Exception can be handled using try and catch block
Exception is of two types
1-CheckedException - must be cached and handled at Runtime
2-UncheckedException
2-Can we write any statement between try and catch block
No it will sue you
3) There are three statements in a try block – statement1, statement2 and statement3. After that there is a catch block to catch the exceptions occurred in the try block. Assume that exception has occurred in statement2. Does statement3 get executed or not?
No statement3 will never executed in this case
4)What is unreachable catch block error?
try
{
int i = Integer.parseInt("abc"); //This statement throws NumberFormatException
}
catch(Exception ex)
{
System.out.println("This block handles all exception types");
}
catch(NumberFormatException ex)
{
//Compile time error
//This block becomes unreachable as
//exception is already caught by above catch block
}
5) What is Re-throwing an exception in java?
if you throw any exception in the catch block, its called re-throwing the exception
Comments
Post a Comment