Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Error-causing code</p> <pre><code> sub whatever { die "OH NOES" if an_error($occurred); } </code></pre> <p>Your main program:</p> <pre><code> use Try::Tiny; # essential my $logger = anything_you_want; try { whatever; } catch { $logger-&gt;error("Error: $_"); }; </code></pre> <p>Throw exceptions when anything goes wrong. Handle exceptions where ever it makes sense; usually at the top level.</p> <p>Sometimes you can "fix" an exception; example: connect to a failover server if the main server is unavailable. In that case, handle the failover somewhere higher-level than the top-level application, but somewhere closer than in the "connect" function:</p> <pre><code>sub connect { die "Error connecting: ..." if ...; } sub make_connection { my $connection = try { connect($main_server) }; $connection ||= try { connect($backup_server) }; die "Couldn't connect to either server" unless $connection; return $connection; } </code></pre> <p>You would then handle "Couldn't connect to either server" in your top-level code, instead of each individual connection error.</p> <p>Finally, you could also use the <a href="http://github.com/jrockway/MooseX-Data/blob/master/lib/MooseX/Data/Error.pm" rel="nofollow noreferrer">Error monad</a>. This lets you return failure codes, but it ensures that no code is executed after the failure. (This approach works better for asynchronous event-based code... but most Perl programmers don't like monads and instead try to use exceptions for everything. That's fine, though... exceptions are a great way to handle errors.)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload