<p>If I'm understanding your question correctly, then you get that behavior by default.</p>
<p>If you:</p>
<pre><code>throw new \Exception('Uh oh.');
</code></pre>
<p>Then you'll get the same error handling layout and logic that Craft uses.</p>
<p>You can <a href="https://craftcms.stackexchange.com/questions/478/render-generic-message-error-template-from-plugin/483#483">read here</a> for more information on how that works.</p>

CC BY-SA 3.0
2014-11-04T06:59:45.830Z
... I don't even know why I just didn't try this. Cheers Brad :)
naboovalley
CC BY-SA 4.0
2022-04-05T14:05:29.057Z
Minor note: `throw new Exception('Uh oh.');` might not work if you're inside your own class that extends something else. Add a backslash before Exception to read from "root". `throw new \Exception('Uh oh.');`
InanisAtheos
CC BY-SA 4.0
2014-11-03T17:27:09.797Z
2022-04-06T21:00:11.363Z
2022-04-06T21:00:11.363Z
Brad Bell
<p>Is it possible for me to use the default Craft error-handling/exception-throwing/debug-showing template layout for my own plugin? Let's say something goes wrong and I want to show that to the user in the same style as any other "code related error" for my Plugin.</p>

<p>Could/how would I achieve this?</p>

<plugin-development>
Use default Craft error/exception layout in Plugin
# Use default Craft error/exception layout in Plugin

(Asked by: username_0 on 2014-11-03)

Is it possible for me to use the default Craft error-handling/exception-throwing/debug-showing template layout for my own plugin? Let's say something goes wrong and I want to show that to the user in the same style as any other "code related error" for my Plugin.

Could/how would I achieve this?

**Tags:** plugin-development


---

## 1 answers

### Answer by username_1 on 2014-11-03. Score: 2 | Accepted answer

If I'm understanding your question correctly, then you get that behavior by default.
If you:
throw new \Exception('Uh oh.');

Then you'll get the same error handling layout and logic that Craft uses.
You can read here for more information on how that works.

> **Comments:**
> **username_0**: ... I don't even know why I just didn't try this. Cheers Brad :)  
> **username_2**: Minor note: `throw new Exception('Uh oh.');` might not work if you're inside your own class that extends something else. Add a backslash before Exception to read from "root". `throw new \Exception('Uh oh.');`  

---

