Disclaimer: The materials used in this column are written by VIP students of Kaige Academy. Students have the right to remain anonymous and have the right to final interpretation of the article. Kaige Academy aims to promote VIP students to learn from each other based on public notes.
Custom exception:
The throws method declares what exception is thrown.
Except for the operation class under RuntimeException, you must write throws for other exceptions to throw
this exception to the outside. There are only two options. Otherwise, write a try catch to handle it locally, or else Write throws and take it out to the caller
Note: After writing a try catch statement, be sure to write an output or processing code in the catch, as shown below:
Exception parent class method:
GetMessage() error introduction
printStackTrace() Print out the abnormal information again
printStackTrace(PrintStream) Specify the channel (local file, network) to output
getStackTrace()
Which class, which line, which method, and what is the name of the class in the calling process of the error message
There are other abnormal information hidden in the exception
Abnormal bank example:
first write a banking class
Then write an implementation class and implement it in the bank class
Write an ID class to store its account, password, balance, etc.
Finally, write a test class test