Leser: 1
3 Einträge, 1 Seite |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
sub otto { ... return new BlubbError(...) if $fehlerausloeser; ... return 0, $result; } ... sub uwe { ... my($status, $result) = otto(...); return $status if $status; # Fehler weiterreichen ... } ... # Irgendwo, wo mich Fehler interessieren: my $status = uwe(...); tuWasDamit($status) if $status;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
package ErrorHandling; our $RecordedError; sub error { $RecordedError = [@_]; die; } sub catch(&) { my $code = shift; eval {$code->()}; return $RecordedError; } package Whatever; sub otto { ... error(...) if $fehlerausloeser; ... return $result; } ... sub uwe { ... my $result = otto(...); ... } ... # Irgendwo, wo mich Fehler interessieren: my $status = catch { ... uwe(...); ... }; tuWasDamit($status) if $status;
1 2 3 4 5 6 7 8 9
my $status = catch { my $result; my $ottoStatus = catch {$result = otto()}; doSomethingWith($ottoStatus) if $ottoStatus; error("Wrong number of otto\n") unless $result == 4; doAnything(); }; doSomethingWith($status) if $status;
1 2 3 4 5 6 7 8 9 10 11 12 13 14
package ErrorHandling; our @RecordedErrors; sub error { $RecordedErrors[-1] = [@_]; die; } sub catch(&) { my $code = shift; push @RecordedErrors, 0; eval {$code->()}; return pop @RecordedErrors; }
3 Einträge, 1 Seite |