Question about Java.lang.Error

There are many reports java.lang.Errorsaying that he should not be caught. My question is that this should not be due to the fact that it uses it. Since it is Throwable, so we can catch it in an attempt to catch. I read some messages, as soon as in some situation he should be caught, how to find out these situations.

In short, I want to know what might go wrong when I catch a mistake. What is this process. Why did they make a mistake and its subclasses? If my application should not catch them, then what catches them? Why can't my code handle this caught error? If I just catch one error and write some processing code in the Catch block, will this code not work?

+3
source share
3 answers

The error (especially the VirtualMachineError subclass) indicates that the JVM is facing an internal problem - this means that its internal state can no longer be consistent. If you catch an error and try to recover, the future behavior is undefined. The reason Throwable errors are because they can be thrown - for example, you can do it yourself for errors in the native library from which it is impossible to recover (for example, the library could be written to JVM memory or its internal static state may be damaged ) For all Throwables, the same technique is used to produce walking stacks and stacks, and it would be foolish to have a different mechanism to do the same.

JVM, VirtualMachineErrors, - , - AWTError, ZipError.

, - : AssertionError LinkageError, / . .

+1

( ).

, , , java.lang.Error. : " ". , - . , .

, OutOfMemoryError, . , . . , :

  • (AssertionError, StackOverflowError)
  • (UnsatisfiedLinkError)
  • JVM (OutOfMemoryError)

"" (.. main()), ( ). , , .

+1

- java.lang.Error?

, , , , - . , URL-.

0

Source: https://habr.com/ru/post/1762275/


All Articles