NAME

Try::Lite - easy exception catcher with auto rethrow

SYNOPSIS

use Try::Lite;
try {
    YourExceptionClass->throw;
}
    'YourExceptionClass' => sub {
        say ref($@); # show 'YourExceptionClass'
    };

you can catch base exception class:

package YourExceptionClass {
    use parent 'BaseExceptionClass';
}

try {
    YourExceptionClass->throw;
}
    'BaseExceptionClass' => sub {
        say ref($@); # show 'YourExceptionClass'
    };

you can catch any exception:

try {
    die "oops\n";
}
    '*' => sub {
        say $@; # show "oops\n";
    };

auto rethrow:

eval {
    try {
        die "oops\n";
    }
        'YourExceptionClass' => sub {};
};
say $@; # show "oops\n"

you can any exception catch:

sub run (&) {
  my $code = shift;

  try { $code->() }
    'FileException'    => sub { say 'file exception' },
    'NetworkException' => sub { say 'network exception' };
}

run { FileException->throw };    # show 'file exception'
run { NetworkException->throw }; # show 'network exception'
run { die 'oops' };              # Died

DESCRIPTION

Try::Lite is easy exception catch with Exception classes. Exception other than the all specified conditions are It run rethrow.

THIS IS A DEVELOPMENT RELEASE. API MAY CHANGE WITHOUT NOTICE.

EXPORT

try $code_ref, %catche_rules

AUTHOR

Kazuhiro Osawa <yappo {@} shibuya {dot} pl>

SEE ALSO

try function base is Try::Tiny

LICENSE

Copyright (C) Kazuhiro Osawa

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.