0

In my plugin, I'd like to catch errors when they appear in the control panel, so I can handle them differently. However, from the front-end, I'd like to keep the default Craft-style handling of error messages.

try
{
    // Some code which might produce an error
}
catch (\Exception $e)
{
    if (craft()->request->isCpRequest()) {
        // Do something with $e->getMessage()
    } else {
        // Use default Craft error handling
    }
}

All of that is working for me, just trying to sort out how to do this part...

// Use default Craft error handling

How can I get my error handling to just go back to what Craft was doing by default? I want to make sure my errors still appear in devMode per usual.

1

Just re-throw the exception and pretend like nothing ever happened...

try
{
    // Some code which might produce an error
}
catch (\Exception $e)
{
    if (craft()->request->isCpRequest()) {
        // Do something with $e->getMessage()
    } else {
        // Nothing to see here...
        throw $e;
    }
}
| improve this answer | |
  • Brilliant, thanks Brad! Worked like a charm! – Lindsey D Apr 17 '15 at 22:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.