Throw statements are used in combination with Try-Catch staements to define an user defined exceptions. When an error is caught during execution of a try block, the throw statement is executed and program flow goes to catch statements as needed.
Syntax for Throw statement
- expression – It is expression which gets thrown when error occurs.
Example of user-defined error object throwing error message