Hi, > > I am using CGI::Application for all my CGI scripts now, and only have > > one issue with it at the moment: > > Exception handling. > > CGI::Application handles its own exceptions with a simple die(), but that's > no reason you need to use die(). In your code you could call something > completely different which outputs to STDERR anything you like.
The thing is that I am not so much concerned with printing something to STDERR but with aborting whatever the program was doing and passing control to some other part of the program, that can handle the situation according to its needs. Since the code that "dies" has no idea what action would be appropriate to amend the situation (it will most likely be located in a completely different package, doing something like database access, not even aware of running under CGI at all) it can not just call a 'my_die()'. I believe exceptions (including simple 'die "error43" ') are the best way to implement this kind of control flow. > There is no > need to modify the core CGI::Application base class to allow you to do this. > Simply implement your own exception handling method and call that in places > you would normally catch fatal exceptions. Since this handling method would want to handle all run-modes I think it is easiest to let any unresolved exception propagate all the way through by letting the run-mode die and having the eval-block (that is already there in CGI::Application) take care of it. > If you create a custom parent class (a descendant of CGI-App which is a > parent for all your applications) you could effect a change globally to all > your applications: > > package My::CGI::Application; > use base 'CGI::Application'; > sub my_die { > # Do something special > } > > package My::Widget::Manager; > use base 'My::CGI::Application'; > sub some_run_mode { > my_die("An error has occurred!"); > } In my case, it would be more like this: package My::Widget::Manager; use base 'My::CGI::Application'; sub some_run_mode { eval{ process_cgi_vars(); do_some_file_stuff(); do_some_database_stuff(); fill_template(); } my_die($@) if $@; } And every run_mode would have the same eval block ! (Wrapped into CGI::Application's eval block) > I am reluctant to add special > exception handling to CGI::Application now, because Perl itself has not yet > implemented uniform exception handling. But replacing the original error message with "Error executing run mode '$rm': $exception" is already special handling. I would really appreciate the additional callback method, although I can see why the default implementation I provided (with dumping any refs) meets opposition. If that is not possible, how about just letting the original error/exception pass through? # Process run mode! my $body = eval { $autoload_mode ? $self->$rmeth($rm) :$self->$rmeth() }; warn "Error executing run mode '$rm': $exception" if $@; die $@ if $@; or just # Process run mode! my $body = $autoload_mode ? $self->$rmeth($rm) :$self->$rmeth(); In latter case I could implement my handler by overriding run() in the custom parent class for all my applications: package My::CGI::Application; use base 'CGI::Application'; sub run { my ($self, @args) = @_, eval{ $self::SUPER->run(@args) } $self->exception_handler($@) if $@; } Please excuse my insistence, Thilo ________________________________________________________________ Keine verlorenen Lotto-Quittungen, keine vergessenen Gewinne mehr! Beim WEB.DE Lottoservice: http://tippen2.web.de/?x=13 --------------------------------------------------------------------- Web Archive: http://www.mail-archive.com/cgiapp@;lists.vm.com/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]