Fatal Error triggers Before WP_Error handler

  1. How do I prevent that like a misspelling error crash wordpress?
  2. Why the message it’s not showed ?
  3. How do I must code this specific situation to see my custom error message?
  1. Spell your code correctly, to be blunt.
  2. Because spelling the class incorrectly caused a fatal error.
  3. Is CanvasGraph written to specifically a WP_Error object under any circumstances? is_wp_error() is for manually passing error messages around. It’s not for handling generic PHP errors.

Your code should be spelt correctly, it’s that simple. You shouldn’t be writing custom error messages just because you’ve made typos. That implies that you intend to ship code to users you haven’t even bothered to check for typos. Those need to be fixed before you ever ship it to users.

In development the normal PHP errors that will display or be logged should be sufficient for catching these issues. Writing unit tests would be a way to automatically run through all your code if manual testing isn’t feasible, but that’s too large a topic for a single answer here. This article seems to provide a good introduction though.

The purpose of WP_Error, and is_wp_error() is for WordPress APIs, or those in your own theme/plugin, to be able to manually return error objects to developers that are using them so that they can handle them downstream. For example, if you tried to use get_terms() with an invalid taxonomy, it will return a WP_Error object, because that’s a circumstance that the WordPress developers could anticipate. But if you simply misspell get_terms(), that’s your mistake and you’ll need to use PHP’s fatal error message to catch the problem, either by checking the error log or running tests.