+ 4

Why  should  your  code  typically  not  catch  exceptions  of  type  Error?

5th Jun 2017, 3:28 AM
Anjaneyulu Bairi
3 Respuestas
+ 4
The Error and Exception classes are both subclasses of the Throwable class. Exceptions are some unforeseen conditions that arise during program execution and it is a good idea to handle them in the code. However, an Error, indicates a serious problem in the code that must be resolved. It is a bad idea to catch an Error like we catch exceptions using the try-catch block. And anyways, we can't do much about an error since most of them are related to the JVM itself that is responsible for running the program. The best example is the OutOfMemoryError, the application cannot recover in any way if the JVM is out of memory.
5th Jun 2017, 5:31 AM
Nihar Raote
Nihar Raote - avatar
+ 2
You catch them cause if you don't the program crashes/stops running So I guess if you don't care about that, sure don't catch them. That could typically only be for a project that needs debugging, never for a final product.
5th Jun 2017, 3:31 AM
Rrestoring faith
Rrestoring faith - avatar
0
Sssss
8th Jun 2017, 9:10 AM
Prachi Singh
Prachi Singh - avatar