I am not sure about this answer. I cant find it anywhere. Is it the empty error handling?!
Java try and catch The try statement allows you to define a block of code to be tested for errors while it is being executed. The catch statement allows you to define a block of code to be executed, if an error occurs in the try block.
e is a reference to the instance of the Exception , like s would be a reference to an instance of String when you declare like String s = "..."; . Otherwise you won't be able to reference the exception and learn what's wrong with your code.
'e' is just a parameter its means catch block can recieve an argument and the Data type of argument is exception datatype.
catch can only handle errors that occur in valid code. Such errors are called “runtime errors” or, sometimes, “exceptions”.
It is known as suppressing the exception, or swallowing the exception. May not be a very good practice, unless commented with a very good reason.
We affectionately call this "eating the exception" at work. Basically, it means that something bad occurred, and we are burying our head in the sand and pretending it never happened. At the very least, a good practice is to have a logger.error(e) within that block:
try {
// code here
}
catch (Exception e) { logger.error(e); }
so that you will have it recorded somewhere that an exception occurred.
As far as I know, it's simply called an "empty catch clause" (or perhaps silent exception consumption), and it should generally be avoided (either handle the exception properly or don't try to catch it at all).
This is generally called as ignoring an exception. Other terms used are Consuming an exception silently, Eating an exception etc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With