custom exception

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

image

Note: After writing a try catch statement, be sure to write an output or processing code in the catch, as shown below:

image

Exception parent class method:
GetMessage() error introduction

image

printStackTrace() Print out the abnormal information again
printStackTrace(PrintStream) Specify the channel (local file, network) to output

image

getStackTrace()
Which class, which line, which method, and what is the name of the class in the calling process of the error message

image

There are other abnormal information hidden in the exception

image

Abnormal bank example:
first write a banking class

image

Then write an implementation class and implement it in the bank class

image

image

image

image

image

Write an ID class to store its account, password, balance, etc.

image

image

Finally, write a test class test

image

image

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326473146&siteId=291194637