On Fri, 14 Apr 2000, Robert Jenks wrote:

> We are currently using Linux/Apache/mod_perl (and Stat::INC) with good
> success (thanks to the help of this list) as a replacement for
> WinNT/IIS/Velocigen.  Everything is (now) going good except that we miss one
> of Velocigen's debugging features.  Velocigen would display compiler errors
> to the browser (after a file-change recompile).  
> 
> I'm currently using CGI::Carp qw(fatalsToBrowser), but this only shows
> runtime errors.
> 
> Is there a way to do this?  I've thought about using the Apache
> "ErrorDocument" config to call a perl script which would display the last
> few lines of the error_log, but it wouldn't be very elegant.

robert,

i would suggest wrapping all the meat of you code in an eval, and then
checking for errors on exit.  when things go wrong, you handle the error.
when things are fine, you create output, like so:

package Foo::Bar;

use Apache;
use Apache::Constants qw(:common);
use strict;

sub handler {
    my $r = shift;
   
    eval {
        # put anything here that could possibly error out
        # like database connections, file reads, etc.
    };

    $r->content_type('text/html');
    $r->send_http_header;

    if ($@) {
        $r->print("There was an error: '$@'");
    } else {
        $r->print('Apache/mod_perl rules!');
    }
    return OK;
}

1;

hth,

ky

Reply via email to