yoastcs icon indicating copy to clipboard operation
yoastcs copied to clipboard

Investigate options for sniffs for catching exceptions.

Open herregroen opened this issue 4 years ago • 3 comments

With the 14.0 release we ran into unfortunate issues where we were not catching all our own exceptions, thus leading to fatals.

Because of this we'd like to explore options for sniffs that forbid the usage of functions that can throw exceptions without using try and catch.

So the following would be invalid code:

function_that_can_throw_exception();

With the following being a valid replacement;

try {
  function_that_can_throw_exception();
}
catch( Exception $e ) {
  // Anything, possibly even rethrowing the exception with added context.
  // In which case this function can't be used without catching it.
}

Even rethrowing the exception would help with developer awareness that exceptions have to be dealt with and can't simply be left.

herregroen avatar May 12 '20 12:05 herregroen