Hi All,
I took a look at the Error and Exception::Class modules from CPAN and I've
used
ideas from them to create my own syntax.
I wanted a try catch the caught only the exceptions thrown from Java, not
other exceptions
such a regular "die" calls or internal Inline::Java errors.
So I came up with this:
my $msg = '' ;
try {
$t->f() ;
} ;
catch "java.io.IOException" => with {
my $e = shift ;
$msg = $e->getMessage() ;
} ;
catch "java.lang.Exception" => with {
my $e = shift ;
$msg = $e->getMessage() ;
} ;
So in this case if "f" is not really a member of the "t" package, the block
won't catch that error.
It only catches exceptions thrown from Java methods or constructors.
Cheers,
Patrick
----- Original Message -----
From: "B. K. Oxley (binkley)" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, November 12, 2001 2:35 PM
Subject: Re: try / catch construct in Perl...
> On Mon, 12 Nov 2001, Sam Tregar wrote:
>
> > Well, as far as getting rid of those 'sub's I think you could use a
> > prototype of (&). However, maybe you could consider using one of
> > the exception handling packages on CPAN? Exception and
> > Exception::Class both look like candidates. I think you might be
> > reinventing a wheel here!
>
> You might also look at the excellent Error module on CPAN.
>
>
> Cheers,
> --binkley
>
>