Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'd say it's a matter of preference mainly, but the dedicated emtpy catch looks cleaner to me. Programmers reading your code can be assumed to be familiar with try/catch constructs, and they expect you to sort your catch blocks from specific to general. The usual way people read try/catch constructs is to skim through the catches until they find one that matches what they're looking for (just like the compiler does), and then see what it does. The reader is doing this anyway, so when you have a dedicated empty catch for that exception type, it is immediately obvious that it is a special case and that you're discarding the exception. The built-in type checking logic, OTOH, requires the reader to find the more general exception branch, which is probably way down the list of catch blocks, and then read through the actual logic to find out what happens. I'd say this requires far more reading effort than an empty catch.</p> <p>Another point is that you're supposed to have a good reason for ignoring exceptions; with an empty catch block, it will be immediately obvious to you and anyone who reviews your code that you are ignoring errors, which is good - it means people will notice and be a bit more conscious about such a potential gotcha, and you'll be pushed toward adding a comment that explains why you're doing it. If you bury the ignore-this-exception part inside the handler logic, people might read past it and then wonder why their exception doesn't pop up anywhere.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload