[Catalyst-commits] r14536 - trunk/examples/CatalystAdvent/root/2014

davewood at dev.catalyst.perl.org davewood at dev.catalyst.perl.org
Tue Dec 2 15:25:11 GMT 2014


Author: davewood
Date: 2014-12-02 15:25:11 +0000 (Tue, 02 Dec 2014)
New Revision: 14536

Added:
   trunk/examples/CatalystAdvent/root/2014/6.pod
Log:
article 6, C::CR:CatchErrors

Added: trunk/examples/CatalystAdvent/root/2014/6.pod
===================================================================
--- trunk/examples/CatalystAdvent/root/2014/6.pod	                        (rev 0)
+++ trunk/examples/CatalystAdvent/root/2014/6.pod	2014-12-02 15:25:11 UTC (rev 14536)
@@ -0,0 +1,65 @@
+=head1 Catalyst::ControllerRole::CatchErrors
+
+=head1 Synopsis
+
+Todays calendar entry explains how to deal with uncaught errors in your
+application using L<Catalyst::ControllerRole::CatchErrors>.
+
+=head1 Flexibility
+
+If your L<Catalyst> application throws an error the default behaviour is to
+generate a HTML error page saying something along the lines of
+"Sorry, we fucked up!".
+
+If L<https://metacpan.org/pod/Catalyst#Debug|debugging> is enabled this oage is
+differently and shows the error message and optionally a stacktrace.
+
+L<Catalyst::ControllerRole::CatchErrors> allows you to do custom error handling.
+The following scenarios come to mind.
+
+=over
+
+=item Customize the error page layout.
+
+The L<Catalyst> error page comes with its own CSS and looks entirely
+different then your page design. See also L<Catalyst::Plugin::CustomErrorMessage>
+
+=item Customize the error page content.
+
+Perhaps you want to give some information to your users so they get a clue what
+went wrong.
+
+=item Send a non-HTML error response.
+
+If you have a REST application you don't want to send text/html default errors
+
+=item rethrow an error
+
+Maybe you want to catch some errors and let others be handled by the default
+mechanism. L<Catalyst::ControllerRole::CatchErrors> lets you do that too.
+Just rethrow it.
+
+=back
+
+=head1 Example
+
+    package MyApp::Controller::Root;
+    use Moose;
+    BEGIN { extends 'Catalyst::Controller' }
+    with 'Catalyst::ControllerRole::CatchErrors';
+
+    sub catch_errors : Private {
+        my ($self, $c, @errors) = @_;
+        # stuff
+    }
+
+=head1 Conclusion
+
+This module was written as a proof of conecpt and might be moved into the
+L<Catalyst> core at some point in the future.
+
+=head1 Author
+
+David Schmidt L<davewood at cpan.org|email:davewood at cpan.org>
+
+=cut




More information about the Catalyst-commits mailing list