Java throws an exception in the usage of thorw and throws, and throws thorwthrows
Java exceptions are treated as an object.
All system-defined compilation and running exceptions are automatically thrown by the system and become standard exceptions.
However, in general, java strongly requires the application to complete Exception Handling, give user-friendly prompts, or correct the code to continue running.
1. User-defined exceptions and application-specific exceptions must be defined with throw and throws statements to throw exceptions.
1.1throw is an exception thrown by the statement;
Syntax: throw (exception object); eg: throw e;
Location: In the method body, an exception is thrown and is processed by the statements in the method body.
1.2throws is a declaration that may throw an exception. Indicates that the method may throw an exception or not.
Syntax: throws (exception type ){.......}
Eg: public void do (int a) throws Exception 1, Exception 2 {......}
Location: used after the method declaration to handle an exception thrown by the caller of the method.
Feature: both of them are passive Exception Handling Methods (not this method is not bad), but they simply throw or may throw an exception, but no function will handle the exception, real Exception Handling involves upper-layer function call processing.