Skip Menu |

This queue is for tickets about the Error CPAN distribution.

Report information
The Basics
Id: 36101
Status: resolved
Worked: 10 min
Priority: 0/
Queue: Error

People
Owner: SHLOMIF [...] cpan.org
Requestors: EDAVIS [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.17012
Fixed in: (no value)



Subject: try {} doesn't catch error thrown by die
I ran this test program: #!/usr/bin/perl use warnings; use strict; use 5.010; use Error; try { die 'x' } otherwise { say "error: $_[0]" } I expected it to print 'error: x' or similar, but instead it said 'x at /home/eda/test line 7.' Does a try block not work to catch exceptions thrown with die? Is an otherwise block not the correct way to catch any exception thrown in the try block? Perhaps I have misunderstood the documentation.
On Thu May 22 11:11:21 2008, EDAVIS wrote: Show quoted text
> I ran this test program: > > #!/usr/bin/perl > use warnings; > use strict; > use 5.010; > use Error; > try { die 'x' } > otherwise { say "error: $_[0]" } > > I expected it to print 'error: x' or similar, but instead it said 'x at > /home/eda/test line 7.' > > Does a try block not work to catch exceptions thrown with die? Is an > otherwise block not the correct way to catch any exception thrown in the > try block? Perhaps I have misunderstood the documentation.
Hi! Sorry for the late response. Your problem is that you have {{use Error;}} instead of {{use Error qw(:try);}}. The following program works: {{{{{{{{ #!/usr/bin/perl use warnings; use strict; use Error qw(:try); try { die 'x'; } otherwise { print "error: $_[0]\n"; }; }}}}}}}}
Antoher qw(:try) problem - closing.