Exception handling for Java compilation

after compiling exception capture, what do you usually do, just simply print the exception information?

Feb.26,2021

compilation is wrong. There must be something wrong with the code. In addition to changing the problematic code to make the program compile, what else do you want to do?


according to the summary of the second edition of "Effect Java":
exceptions are divided into:

  1. checked exception (checked exception,. By compiler exception, you mean this, right?
  2. Runtime exception (runtime exception)
  3. error (error)

Runtime exceptions and errors are thrown structures that are not needed and should not be caught. If the program throws a runtime exception or error, it means that there is an unrecoverable situation, and it will do more harm than good to continue execution. If such a structure is not captured, it will cause the current thread to stop and an appropriate error message will appear.

principles of use:

  1. if the caller is expected to recover appropriately, the checked exception is used for this case.
  2. indicates programming errors with run-time exceptions.
  3. if it is not clear whether recovery is possible, an unchecked exception is used.
Menu