There are various concepts here. 1st nothing says that 
Apache::AxKit::Exception based exceptions are the 'right' ones to throw, in 
fact unless the code is part of AxKit why would you throw an AxKit exception? 
The type of an exception should tell you WHERE it came from and maybe WHAT 
its for if you need that distinction. 

Thus I would generally THROW exceptions of my own devising. If you can't think 
of a particular exception you want to throw then why bother to catch whatever 
exception was thrown below your code at all? Just let it through to higher 
levels, which presumeably know better how to handle it.

Throwing and catching exceptions should be relatively straightforward, just 
perldoc on the 'Error' module, it gives you a complete try/catch syntax and 
its what AxKit already uses internally. If all you need to do is throw an 
exception its possible to just call 'die' and give it an object reference 
instead of a string too. Personally eval {} and if($@) was always good enough 
for me...

Exception::Class based exceptions work just slightly differently from Error 
based exceptions. Check the very bottom of the Exception::Class POD and it 
has something to say about that, you need to patch @ISA or some such 
foolishness to get try/catch to catch Exception::Class. 

At the top level AxKit should never see exceptions. That is to say that being 
a toolkit it really has no useful way to deal with them, hence the 'unknown 
exception' stuff. Either catch them in your taglib code and generate sensible 
error messages/behaviour or else wrap the offending code using the exception 
taglib and do the same. Another alternative which can be handy is to use 
Apache's ErrorDocument facility. 

On Friday 23 January 2004 5:34 pm, Kjetil Kjernsmo wrote:
> Hello World!
>
> I'm working with some data objects that throw Exception::Class::DBI if, for
> some reason, the database doesn't what you expect. Well, yeah, I did write
> these data objects myself, and Exception::Class::DBI seemed right since
> they are intended for the use of DBI, I (think I) know I could in principle
> let the DBI throw an Apache::AxKit::Exception, but for various reasons...
> well, lets just say for the sake of the argument, that a
> Exception::Class::DBI has been thrown by a module I can't modify, and I
> want to get some more sensible things in the error logs than "unknown
> exception"...
>
> I'm not quite used to working with exceptions yet, but I realize the great
> value compared to other types of error handling, so I'd really like to use
> them.
>
> So, what I figured is that I'll just catch the exception, and then throw a
> Apache::AxKit::Exception::IO instead, with the error string from the
> Exception::Class::DBI as -text. This would be the standard way to do it,
> and for now, I can't think of a situation where I would like to do it
> differently, and since I'm Lazy, I therefore would like to write that code
> only once. I have a bunch of Taglibs and Providers, and they inherit stuff
> from things higher in the hierarchy. So I guess I could implement the catch
> there. But I after having thought about it for some time, I couldn't
> imagine any way to do it...
>
> So, instead, I started playing with a situation where I have a known bug
> that causes the database to fail and throw a Exception::Class::DBI::STH.
> Still, in this situation, I did not find a way to accomplish what I wanted.
>
> The error happens under some circumstances when my Taglib instructs the
> object to save itself (i.e. INSERT itself into the database table). So, I
> thought I'd just put the catch immediately after the save, like this:
>     $story->save();
>     catch Exception::Class::DBI with {
>       my $ex = shift;
>       throw Apache::AxKit::Exception::IO(
>                                          -text => $ex->error
>                                          );
>       }
>
> What happens here is that an exception is thrown in the save(), and I was
> hoping to catch it immediately afterwards.
>
> But apparently, that's not how it works, this is how the error log looks:
>  [Fri Jan 23 23:05:02 2004] [warn] [client 127.0.0.1] [AxKit] Caught an
> exception
> Use of uninitialized value in subroutine entry at
> /usr/local/lib/perl/5.6.1/AxKit.pm line 332.
> [Fri Jan 23 23:05:02 2004] [error] Unknown exception, type:
> Exception::Class::DBI::STH at /usr/local/lib/perl/5.6.1/AxKit.pm line 391.
>
> So, I'm wondering, how should I go about to do this Right?
>
>
> Cheers,
>
> Kjetil
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]

-- 
Tod Harter
Giant Electronic Brain
http://www.giantelectronicbrain.com


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to