> Hello List,
> 
> I am using a module that does use Carp; and you 
> can specify whther you want croak or carp on an error
> Which is cool. But there is no way to specify anythign 
> else besides those two.
> 
> So the way it is you just do:
> 
> my $res = funktion('foobarmonkey',err_doer => 'carp');
> 
> And it will do 
> carp('what  the heck is foobarmonkey');
> 
> What I'd like to do is get any errors into a variable:
> 
> my $err = '';
> my $res = funktion('foobarmonkey',err_doer => 'puterrorinvar');
> 
> if($err) {
>       print "Error: $err\n";
>       print "Logging error..."'
>       if(logerror($err) { print "Ok\n"; } else { print "Failed!\n"; }
>       print "Emailing Admin...";      
>       if(emailadmin($err)) { print "Ok\n"; } else { print "Failed!\n"; }
>       # and now that we did that we can go ahead and carp, craok die, whatever       
>  
> }
> 
> Except I can't simply specify a new function for errors because it
checks for what you enter to see if its in a hash and if not defaults to
one or the other. (I could modify the module but then it won't work for all)
> 
> SO I guess the question is, is there a way to get carp or croak into a
variable?
> Something like this perhaps: ?
> 
> my $err = '';
> putcarpinvar_on(\$err);  # this is an example to illustrate what I'm
shooting for it is not real
> my $res = funktion('foobarmonkey',err_doer => 'puterrorinvar');
> putcarpinvar_off(\$err); # this is an example to illustrate what I'm
shooting for it is not real
> if($err) { ...
> 
> Any ideas?
> 

It appears you are talking about exceptions in a try/catch manner?  You
may want to look at 

perldoc -f die
perldoc -f eval

And see if the mess of docs there helps. It is pretty scattered at least
to me, but I think it will provide what you want.  An example might be,

my $res = eval {  call_function() };
if ($@) {
   # $@ contains your variable's value
}

# else process $res here

This seems like it would simulate what you are after.  Because croak is
just a replacement for 'die' it should work the same way giving you the
same benefits.  It is really the 'eval' that is the significant part of
the construct despite it being explained in the 'die' docs...

I have a cursory understanding of standard exception models, and have
built my own version for Perl modules that doesn't quite fit into the
above (yet!), but reading the Learning Python book has helped solidify
my understanding and suggesting the changes I need to make to my own
implementation.

Thoughts?

http://danconia.org


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to