yoastcs icon indicating copy to clipboard operation
yoastcs copied to clipboard

Investigate options for forbidding throwing exceptions in specific directories.

Open herregroen opened this issue 4 years ago • 3 comments

In our integrations directory we have all our classes that hook into WordPress filters and actions. As any exceptions thrown here in public functions wouldn't be able to be caught by us these would likely lead to fatals.

So ideally we'd be able to specify directories where throwing exceptions would be forbidden in public functions under the expectations that these would be hooked into WordPress filters ( if it's possible to detect which functions are hooked into filters or actions that would be excellent as well but I can see that being rather more difficult ).

So the following code would be forbidden only in public functions in a given directory:

throw new Exception( "Error!" );

While the following would be allowed:

return false;

herregroen avatar May 12 '20 12:05 herregroen