3

Is there a way to 'whitelist' - or prevent - specific errors from being thrown in a try catch block?

For instance, say I have an exception that I know about and don't want to log. However, I want to catch any other errors that pop up in that try/catch block.


This is the best that I can come up with:

try {
...
} catch(exception) {

    //Loop through a predefined list of known errors that we want to ignore.
    for (var i in whitelistOfErrors) {

        //if our exception MATCHES an error that we want to ignore,
        //don't throw it
        if (exception == whitelistOfErrors[i])
            break;

        //if our exception DOESN'T MATCH an error that we want to ignore,
        //throw it
        if (i = whitelistOfErrors.length)
            throw exception;
    }
}

(or replace the logic with a method that searches the array for you, if that exists)

Lemmings19
  • 1,383
  • 3
  • 21
  • 34

0 Answers0