Gregory Matthews wrote:
> Thank you for the link.

[Gregory, please remember to keep the threads on the list and not to 
take them private without being asked to and worse, not sharing the 
knowledge with the rest of the community]

> This is the route I would like to go (My::Exeption). Could you please 
> provide a simple example of how I would utilize this in my code.

If you have the mod_perl cookbook, check the recipe 8.6 (it's not online).

otherwise depending on your needs you simply generate the response and 
set the return code accordingly. For example as 8.6 suggests:

   use Apache::Constants qw(SERVER_ERROR);
  $r->custom_response(SERVER_ERROR, "send more coffee");

Can somebody please submit a patch to this doc
http://perl.apache.org/release/docs/general/perl_reference.html#Exception_Handling_for_mod_perl
 

with a nice complete example, which does the exception handling and 
generates a custom error response to user plus does the logging? The 
existing material is nice, but misses real examples.

> For example, I've uploaded "Exeption.pm" to the "My" directory.
> 
> I've inserted "use My::Exeption;" into my code.
> 
> Now, if I want to catch an internal server error and display a custom 
> message based on what caused the error, how would I call this module 
> from my code?
> 
> For example, say I try to load a module, "use HTML::Template", which is 
> not available.

that would be a complile time error, which you cannot catch with eval 
{}, you must use 'require() HTML::Template' for performing the run-time 
testing.

> This would cause an internal server error that I would 
> like to catch and display in neatly formatted HTML stating that.

The idea is that you try {} catch {} in perl:

eval {
     require "oops_i_did_it_again";
};
if ($@) {
     my_exception_handler($@);
}

now inside my_exception_handler you do whatever you want, log to 
error_log and send a nice error message to a user, or just log and 
return SERVER_ERROR, or just send a message to a user if it's a user 
error. Matt's section was showing how to use AUTOLOAD to autovivify 
packages for each exception, but in really it should be a solid set of 
classes that you should write. So start from the example above and work 
from there.

The simplest my_exception_handler does:

sub my_exception_handler { die $_[0] }



__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

Reply via email to