Use default Craft error/exception layout in Plugin
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.