keshav pradeep ramanath wrote:Create a class with a main( ) that throws an object of class Exception inside a try block.
Give the constructor for Exception a String argument.
Catch the exception inside a catch clause and print the String argument.
Add a finally clause and print a message to prove you were there.
Please give the solution for the same."Please explain how to use Exception constructor".
K.that was very nice on you to suggest me to do tge code by myself!!
public class FirstException
{
FirstException(String msg)
{
msg="this is bound to execute";
System.out.println(msg);
}
public static void main(String[] args)throws Exception
{
try
{
throw new Exception();
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
System.out.println("i will get printed");
}
}
}
I am not knowing the way to throw an object of class Exception inside a try block!!!Please help...Is it possible to throw an exception in try block??please suggest!!!