Leser: 23
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
sub worker_sub {
print "worker_sub\n";
croak "testerror";
}
sub worker {
eval ( worker_sub() );
if ($@) {
print "ERROR\n";
}
sleep 2;
}
my $mythread = threads->create( \&worker );
eval ( worker_sub() );
eval { worker_sub() };
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
sub worker_sub {
croak "testerror";
}
sub worker {
eval { worker_sub() };
if ($@) {
croak $@;
}
sleep 2;
}
my $mythread = threads->create( \&worker );
...
croak $@;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#!/usr/bin/env perl use strict; use warnings; use threads; sub worker_sub { die "Ups!\n"; } my $worker = async { eval { worker_sub }; $@ }; my $error = $worker->join(); if ($error) { print "The worker thread produced an error: $error"; } else { print "The worker thread completed successfully\n"; }
no warnings 'threads';
$thr->error()