Java's Exception] [General specification in project development

This problem has been troubled for several days, the answer to the above Department after nearly two full days widely read books, blog, online quizzes, induction and trying to come together.
Bowen listed Total views only, a detailed explanation of each view can be private letter Word notes.
When For reprint or copy, please indicate the source.
Published in this blog know almost synchronous: the Java exception handling mechanism, when should throw an exception, when to catch the exception?

A general specification --1

0 [capture] the delay, as soon as possible [throw], [within their means] the line.
1 ☆ avoid capture not avoidable Unchecked exception] [
2 ☆ [do not abnormal flow / control conditions]
3 ☆ finally blocks: resource objects must be closed, the stream object; when abnormality should also try-catch capture;
4 ☆ return statement: can not be used in the finally block
5 ☆ exception thrown: = abnormal parent abnormal OR captured thrown
6 △ error code For External API | For user-friendly prompts terminal | Throws For internal applications
7 △ null method: allows is null, detailed comments need to
8 △ prevent NPE

Two exceptions thrown - 2

1 [WHEN] notification signal: transfer signal, must inform the [caller]
2 [WHEN] powerless: [callee / present method None ability to handle exceptions, [caller] has the ability to process
3 [WHEN] frame considerations: [framework] require level
4 △ [WHAT] cast concrete | abnormal traffic, ban throw Throwable | Exception | RuntimeException

Three capture variations --3

1 from the specific to the general: Capture / exception processing sequence of N
2 ☆ unsteady code: [unsteady capture only possible exception codes]
3 ☆ top caller: content must handle the exception, the user is converted into understandable
4 ☆ rollback transaction: manually try to roll back the transaction in the transaction code block

references

[0] Java programming language - South China University of Technology Press (Zhenfei with Sun Yuan)
[1] Alibaba Development Code Handbook
[2] in Java's exception handling mechanism, when should throw an exception, when to catch the exception? -Zhihu
[3] the Java proper use of abnormal posture - OSChina

Guess you like

Origin www.cnblogs.com/johnnyzen/p/12329624.html