How to Raise an Exception using Throw Keyword and How to use Finally Keyword in Core Java

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”);
}
}
}

Add a Comment

Your email address will not be published.