Skip to content

Use a custom Exception child to signal a return from prepare_data() and/or logger #3

@johnpbloch

Description

@johnpbloch

In the comments on the announcement post, Shaun Harding brought up the point that it's a bit counter intuitive to use an exception to tell the runner not to create an async task:

No offense... but this is really annoying...

try {
  $data = $this->prepare_data( $data );
} catch ( Exception $e ) {
  return;
}

If you're going to throw an exception, and go through the trouble of catching it, don't ignore it...

He followed up with another good point:

The intent may not be to catch errors, but should an exception get thrown due to an error, it will be caught and promptly ignored. If you're only looking to catch a very specific type of exception, then a specific type of exception should be defined. If you really must catch all exceptions, then logging the exception would be nice. There's no xdebug.scream to undo that suppression.

Let's use this issue thread to discuss the merits of the approaches he's suggesting:

  1. Use a custom Exception child class, or
  2. Add some sort of logging to the process that will log the exceptions that occur

We could even use both together to allow the logger to differentiate between different types of exceptions but still catch all types.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions