I had to run a shell program exiting with an error from Perl 6, so I've decided to test how it works.
I've made a bash
script producing an error to run it from a Perl 6 program:
$ cat prog.sh
echo "error" >&2
exit 1
Here is how I call it from Perl 6:
put "start";
try {
shell "./prog.sh";
}
put "end";
The output shows that the program exited after running the shell command.
start
error
The spawned command './prog.sh' exited unsuccessfully (exit code: 1)
in block <unit> at b.p6 line 2
If I add a CATCH
block
put "start";
try {
shell "./prog.sh";
CATCH { default {} }
}
put "end";
everything is OK, and the program works to the last line:
start
error
end
So my question: why is it necessary to add the CATCH
block, while try
by itself cannot tackle the error?
shell
command throw an Exception only aftersink
? Is it a property of the shell itself or the way Perl 6 handles it? The docs onsink
are very short, so I don't fully understand the concept. – Lapboard