Advertisement
try
{
// An object of IOException exception class is created using "new" keyword.
throw new IOException();
}
catch(IOException io)
{
throw io; // An existing exception class object referenced by "io" of type "IOException", is thrown.
}
import java.io.*;
class ThrowEx
{
public static void main(String... ar)
{
try
{
throw new IOException(); // "throw", explicitly throws an exception object of type "IOException"
}
catch(IOException ioExp)
{
System.out.println("Thrown Exception - " +ioExp);
}
}
}
Thrown Exception - java.io.IOException
Advertisement
class A
{
public static void main(String... ar)
{
try
{
Integer i = new Integer("One"); //throws NumberFormatException
}
catch(Exception e)
{
System.out.println("Exception caught - "+e);
System.out.println("Caught exception is thrown again");
throw e; //throwning the caught exception
}
}
}
Exception caught - java.lang.NumberFormatException: For input string: "One"
Caught exception is thrown again
Exception in thread "main" java.lang.NumberFormatException: For input string: "One"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.(Unknown Source)
at A.main(A.java:8)
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement