KHLeow has asked for the wisdom of the Perl Monks concerning the following question:
Hello wise monks. Many thanks for helping me identify the source of the problem that is the cmd.exe QuickEdit mode last time.
But now I need your wisdom again.
Suppose we have two perl files, parent.pl and child.pl. We start by running parent.pl, which will start another process to run child.pl. How do I propagate the errors in child.pl to parent.pl.
This is parent.pl
And this is child.pl
As you can see, what I'm trying to do is to iterate to the next loop (instead of simply die-ing) when a custom exception is caught. This works if the code inside the eval block is still in same process. However, eval does not seem to be able to catch errors that are in another process. I have tried some modules like Error and Error::TryCatch as well but nothing works.
But now I need your wisdom again.
Suppose we have two perl files, parent.pl and child.pl. We start by running parent.pl, which will start another process to run child.pl. How do I propagate the errors in child.pl to parent.pl.
This is parent.pl
#!/usr/bin/perl use Win32::Process; for (1..3) { eval { print "$_\n"; Win32::Process::Create(my $proc, $^X, "perl child.pl", 0, 0, "."); }; if ($@) { if (index($@, 'Custom Exception') == 0) { print "Caught exception: $@"; next; } else { die $@; } } }
And this is child.pl
#!/usr/bin/perl die 'Custom Exception';
As you can see, what I'm trying to do is to iterate to the next loop (instead of simply die-ing) when a custom exception is caught. This works if the code inside the eval block is still in same process. However, eval does not seem to be able to catch errors that are in another process. I have tried some modules like Error and Error::TryCatch as well but nothing works.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: eval-ling code in another process
by targetsmart (Curate) on Jun 02, 2009 at 09:15 UTC | |
Re: eval-ling code in another process
by lakshmananindia (Chaplain) on Jun 02, 2009 at 09:46 UTC | |
Re: eval-ling code in another process
by ikegami (Patriarch) on Jun 02, 2009 at 14:42 UTC | |
Re: eval-ling code in another process
by KHLeow (Novice) on Jun 02, 2009 at 10:12 UTC | |
by wol (Hermit) on Jun 02, 2009 at 15:48 UTC | |
by Errto (Vicar) on Jun 02, 2009 at 15:29 UTC |
Back to
Seekers of Perl Wisdom