02-09-2017, 04:00 PM
The throw keyword in Java is used to explicitly throw an exception from a method or any block of code. The general way of launching is as follows:
launch instance
But this exception, that is, the instance must be of the Throwable type or a subclass of Throwable. For example, Exception is a subclass of Throwable and user-defined exceptions often extend the Exception class. Unlike C ++, data types such as int, char, floats, or non-throwable classes can not be used as exceptions.
The program execution flow stops immediately after the throw statement is executed and the nearest include try block is checked to see if it has a catch statement that matches the exception type. If it finds a match, the control is transferred to that statement, otherwise the next try block is blocked and so on. If no matching catch is found, the default exception handler will interrupt the program.
launch instance
But this exception, that is, the instance must be of the Throwable type or a subclass of Throwable. For example, Exception is a subclass of Throwable and user-defined exceptions often extend the Exception class. Unlike C ++, data types such as int, char, floats, or non-throwable classes can not be used as exceptions.
The program execution flow stops immediately after the throw statement is executed and the nearest include try block is checked to see if it has a catch statement that matches the exception type. If it finds a match, the control is transferred to that statement, otherwise the next try block is blocked and so on. If no matching catch is found, the default exception handler will interrupt the program.