Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can leaving a Catch block empty cause issues in JavaScript

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?
 }
like image 688
Showcaselfloyd Avatar asked Sep 21 '16 17:09

Showcaselfloyd


1 Answers

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.

like image 75
Michael Armes Avatar answered Oct 12 '22 19:10

Michael Armes