I'm working on a large code base and trying to refactor a bunch of old javascript code. My boss pointed out that there are a lot of try{ }catch(err){ }
blocks in the code where the developer left the catch
block empty.
Anyhow, is there any harm in leaving these blocks of code empty? I've heard it can causes issues in Java, but is there any harm in the case of JavaScript.
Example:
try {
if (value != null) {
var typeOne = report;
returnVal = formatB;
}
} catch (err) {
// Is this bad?
}
From what I've seen in most languages I've worked with, empty Catch blocks swallow errors and make debugging really tricky. It would be kinder to log the exception somewhere, or throw it to the UI level in an error message, or to an error-handling method where it's treated appropriately, at least in my experience. Otherwise you may end up with buggy behavior and have a load of difficulty tracking it down.
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