Sentry-php: Question: Can we log a captured exception?

Created on 6 Jul 2020  路  5Comments  路  Source: getsentry/sentry-php

I'm using Laravel 5.x ... 7.x

I ask you if there is a way to log via Sentry an already captured Exception, in a catch block I mean.

Question

All 5 comments

This is normally done with:

try{
    // ...
} catch(\Throwable $e) {
    captureException($e);
}

If the exception does not rise, it's not captured automatically. For other details, @stayallive knows more since he maintains sentry-laravel.

^ this is the way to do this.

If you want to use the Laravel container it could look more like this:

try {
    // your code that could throw an exception
} catch (\Throwable $e) {
    if (app()->bound('sentry')) {
        app('sentry')->captureException($e);
    }
}

You can also use which should also log the exception to your log files:

try {
    // your code that could throw an exception
} catch (\Throwable $e) {
    report($e); // this is a Laravel helper, not from Sentry
}

Your choice what makes the most sense in your situation.

It works thanks.

I cannot find it in the documentation, if missing I suggest to addd

It's here so I think we got it covered :)

https://docs.sentry.io/platforms/php/#capturing-errors

Thanks for all help.

I was looking only into api doc, thanks for pointing me to right doc page

Was this page helpful?
0 / 5 - 0 ratings

Related issues

parichayawalia picture parichayawalia  路  3Comments

iluuu1994 picture iluuu1994  路  7Comments

JanMikes picture JanMikes  路  4Comments

Nix-id picture Nix-id  路  5Comments

m1guelpf picture m1guelpf  路  7Comments