java | throws example
//Example of Throws
class ThrowsDemo
{
static void call()throws NullPointerException //Exeption fired by method but not handled
{
//try without catch
throw new NullPointerException("Exeption fired by me");
}
}
class Test
{
public static void main(String ar[])
{
try
{
ThrowDemo.call();
}
catch(NullPointerException e)
{
System.out.println("Exception fired by throw handled here [in main catch]"+e);
}
}
}
0 comments:
Post a Comment