in reply to Trap errors in entire module...

Given that your script is OK, and you're only looking for errors in other modules, you can put:
BEGIN {use CGI::Carp qw(fatalsToBrowser);}
as the first statement in your file, and they will go to the browser.

I just tested putting this begin statement after the use call for the module with an error in it, and you only get erros in browser if the BEGIN is before the use.

Replies are listed 'Best First'.
Re: Re: Trap errors in entire module...
by kiat (Vicar) on Mar 28, 2004 at 09:42 UTC
    Thanks, matija!

    Is it possible to use 'warn' or a custom bail out subroutine there instead of 'use CGI::Carp qw(fatalsToBrowser);}?

      Naturally: there is nothing magical about CGI::Carp after all: look at it's code, and you'll see how it does it's work.

      Once you understand it, there should be no problem adapting it to your needs.

        Hey matija,

        I'm trying to have something like the following in place of CGI::Carp but it doesn't work. What's the correct way to do it?

        BEGIN { if ($@) { # This print html error code will go into a sub within # the main script. It's here for illustration purposes. print qqContent-type: text/html\n\n~; print qq~<html>\n~; print qq~<head>\n~; print qq~<title>Error</title>\n~; print qq~</head>\n~; print qq~<body>\n~; print qq~A fatal error has occurred blah blah...\n~; print qq~</body>\n~; print qq~</html>~; exit; } }