Page 174 - CTS - CSA TP - Volume 2
P. 174
COMPUTER SOFTWARE APPLICATION - CITS
1 Custom Exception Class:
Define a custom exception class CustomException that extends the Exception class.
2 Main Method:
• Declare the main method.
3. Try Block:
• Invoke the method throwCustomException() that throws a custom exception using the throw keyword.
4 Catch Block (CustomException):
• Catch the custom exception and print a message.
5 Finally Block:
• The finally block contains code that will always be executed, whether an exception is thrown or not.
6 Throw Custom Exception Method:
• Define a method throwCustomException() that throws a custom exception.
159
CITS : IT & ITES - Computer Software Application - Exercise 108