You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
start() pauses the parent until the child executes the command or CODE reference and propagates any exceptions thrown (including exec() failure) back to the parent. This has several pleasant effects: any exceptions thrown in the child, including exec() failure, come flying out of start() or run() as though they had occurred in the parent.
However, unless I'm totally misunderstanding things, this doesn't happen. Here's some sample code:
use IPC::Run 'run';
print STDERR "Parent $$\n";
sub child {
print STDERR "Child $$\n";
die("Child dies");
}
sub parent {
run \&child;
}
eval { parent } ;
if ( $@ ) {
print "$$ error: $@\n";
}
else {
print "$$ no error\n";
}
Here's what I expect to happen.
Parent runs child
Child dies, returns immediately from die() to parent
Exception is magically massaged so that run() in parent throws child's exception
eval in parent catches child's exception.
Here's some output:
Parent 26043
Child 26086
26086 error: Child dies at ../../IPC-Run/child_dies2.pl line 9.
26043 no error
Notice that it is the child that catches the error and prints it, actually continuing (because run is not trapping the error) to execute after the end of the child subroutine when it should have returned to the parent. The parent does not see the exception at all.
The text was updated successfully, but these errors were encountered:
When a Perl subroutine is run as the child, I expect that an exception thrown in the sub will get propagated up to the parent,
From the fine manual
However, unless I'm totally misunderstanding things, this doesn't happen. Here's some sample code:
Here's what I expect to happen.
die()
to parentrun()
in parent throws child's exceptioneval
in parent catches child's exception.Here's some output:
Notice that it is the child that catches the error and prints it, actually continuing (because
run
is not trapping the error) to execute after the end of thechild
subroutine when it should have returned to the parent. The parent does not see the exception at all.The text was updated successfully, but these errors were encountered: