Вопрос по perl – Как правильно использовать try catch в perl, который выдает error.pm?

29

Error: User Rate Limit ExceededError: User Rate Limit ExceededError: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

try {
    // do something that will fail!

} catch (Error e) {
    // Print out the exception that occurred
    System.out.println(e.getMessage());
}

Error: User Rate Limit Exceeded

Ваш Ответ

3   ответа
44

eval {
    die "Oops!";
    1;
} or do {
    my $e = [email protected];
    print("Something went wrong: $e\n");
};

try, throw[email protected][email protected]

# BAD, DO NOT USE WITH PERLS OLDER THAN 5.14
eval {
    die "Oops!";
};
if (my $e = [email protected]) {
    print("Something went wrong: $e\n");
}
# BAD, DO NOT USE WITH PERLS OLDER THAN 5.14

autodie

use feature qw(switch);

eval {
   use autodie;

   open(my $fh, '<', $some_file);

   my @records = <$fh>;

   # Do things with @records...

   close($fh);

};

given ([email protected]) {
   when (undef)   { say "No error";                    }
   when ('open')  { say "Error from open";             }
   when (':io')   { say "Non-open, IO error.";         }
   when (':all')  { say "All other autodie errors."    }
   default        { say "Not an autodie error at all." }
}

.

Error: User Rate Limit ExceededevalError: User Rate Limit Exceeded
Error: User Rate Limit Exceeded pitchblack408
Error: User Rate Limit Exceededthe BACKGROUND section in Try::Tiny docsError: User Rate Limit ExceededperlError: User Rate Limit ExceededevalError: User Rate Limit Exceeded
5

49

perls.

use Try::Tiny;

try {
        die "foo";
} catch {
        warn "caught error: $_";
};
Error: User Rate Limit Exceeded pitchblack408
Error: User Rate Limit ExceededdieError: User Rate Limit ExceededcroakError: User Rate Limit Exceeded
Error: User Rate Limit ExceededTry::TinyError: User Rate Limit ExceededreturnError: User Rate Limit Exceededtry/catch/finallyError: User Rate Limit Exceeded
Error: User Rate Limit Exceeded pitchblack408

Похожие вопросы