Error classes in Java
I try to understand the error class in Java
I have a good understanding of the exception class, but I can't find the code example of the error class I have tried to search web pages and Java Sun website, but I didn't find any useful help to better understand this
How to use the error class in the program and where do we have to use it?
Solution
You should not use errors in your code
An error is a specific throwable, just like an exception
>Throwable is the base class that defines all the contents that can be thrown. > Exceptions are common This is about problems that occur during the execution of the procedure
>RuntimeException is a special case: it is unchecked (that is, it does not require a method declaration, and the compiler does not force you to catch it)
>Error is a "rare" situation: it indicates problems that are not controlled by conventional applications: JVM errors, insufficient memory, problems verifying bytecode: These are things you should not deal with, because if what happens to them is bad, your code is unlikely to handle it correctly
You should not attempt to correct the situation that caused the error You may want to capture it to record it and then re throw it (see an example of @ l_404_5 @ in Javadoc, why do you need to re throw it (thank @ Krock for the unit))
There is no other reason to throw any errors (i.e. don't create an error and throw it yourself. If you think you want to do so, use an exception or runtimeException)