<p>Just re-throw the exception and pretend like nothing ever happened...</p>

<pre><code>try
{
    // Some code which might produce an error
}
catch (\Exception $e)
{
    if (craft()-&gt;request-&gt;isCpRequest()) {
        // Do something with $e-&gt;getMessage()
    } else {
        // Nothing to see here...
        throw $e;
    }
}
</code></pre>

CC BY-SA 3.0
2015-04-17T22:03:35.013Z
Brilliant, thanks Brad! Worked like a charm!
Lindsey D
CC BY-SA 3.0
2015-04-17T22:01:08.670Z
2015-04-17T22:01:08.670Z
Brad Bell
<p>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 <em>default</em> Craft-style handling of error messages.</p>



<pre class="lang-php prettyprint-override"><code>try
{
    // Some code which might produce an error
}
catch (\Exception $e)
{
    if (craft()-&gt;request-&gt;isCpRequest()) {
        // Do something with $e-&gt;getMessage()
    } else {
        // Use default Craft error handling
    }
}
</code></pre>

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

<pre class="lang-php prettyprint-override"><code>// Use default Craft error handling
</code></pre>

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

<plugin-development><error><error-handling>
Return to default error handling
# Return to default error handling

(Asked by: username_0 on 2015-04-17)

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.

**Tags:** plugin-development, error, error-handling


---

## 1 answers

### Answer by username_1 on 2015-04-17. Score: 1 | Accepted answer

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;
    }
}

> **Comments:**
> **username_0**: Brilliant, thanks Brad! Worked like a charm!  

---

