In this tutorial how to raise an Exception using throw Keyword and how to use finally Keyword in Core Java is shown.
Code:
ExceptionThrow.java
class ExceptionThrow
{
public static void main(String args[])
{
try
{
for(int i=0;i<5;i++)
{
if(i==3)
throw new Exception();
else
System.out.println(“i: “+i);
}
}
catch(Exception e)
{
System.out.println(“Exception raised”);
}
finally
{
System.out.println(“finally is called”);
}
}
}