Page 392 - CITS - Computer Software Application -TT
P. 392
COMPUTER SOFTWARE APPLICATION - CITS
method();
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
System.out.println(“rest of the code...”);
}
}
Output
Example 3: Throwing User-defined Exception
exception is everything else under the Throwable class.
TestThrow3.java
// class represents user-defined exception
class UserDefinedException extends Exception
{
public UserDefinedException(String str)
{
// Calling constructor of parent Exception
super(str);
}
}
// Class that uses above MyException
public class TestThrow3
{
public static void main(String args[])
{
try
{
// throw an object of user defined exception
throw new UserDefinedException(“This is user-defined exception”);
}
379
CITS : IT&ITES - Computer Software Application - Lesson 101 - 108 CITS : IT&ITES - Computer Software Application - Lesson 101 - 108