Skip to content

Introduce way to handle exceptions in closures #85

@PrinsFrank

Description

@PrinsFrank

There is currently not a way to nicely handle all exceptions in closures:

$schedule->run(fn => throw new Exception())

The closure will be serialized and run in a seperate process, so on_error or set_exception_handler won't work. Even setting an exception handler in the closure itself won't work, as the exception is actually caught higher up in the console command, meaning the exception_handler won't be called.

Instead, to handle these exceptions, all closures currently can be wrapped in a try-catch:

$schedule->run(
    static function () {
        try {
            throw new Exception();
        catch (Throwable $e) {
            // log error to somewhere
        }
    }
)

This is the way we are currently handling these, but it would be nice to be able to serialize an exceptionHandler together with the closure. Would you be open to something like that?

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