[prev in list] [next in list] [prev in thread] [next in thread] 

List:       cgiapp
Subject:    Re: [cgiapp] Using Exception::Class with Login module
From:       Sam Tregar <sam () tregar ! com>
Date:       2004-04-16 19:46:18
Message-ID: Pine.LNX.4.58.0404161542130.16502 () localhost ! localdomain
[Download RAW message or body]

On Fri, 16 Apr 2004, dfs dsf wrote:

> Firstly I've read the documentation for
> Exception::Class on the cpan site but didn't get it
> quite right, to be right after reading the document
> I'm confused about how to use the module.

I'm confused about how to read that sentence!  I guess you found the
Exception::Class documentation confusing, right?

> Can anyone give me any guidelines about starting with
> Exception::Class with custom modules or with CGI::App.
> Any sample code would be of great help.

In some module:

  use Exception::Class( 'MyException');

  sub foo {
    MyException->throw( error => 'Something is wrong!!!' );
  }

In your CGI::App module:

  # this call to foo() might throw an exception, better use eval{}
  eval { foo() };
  if ($@ and ref $@ and $@->isa('MyException')) {
     return "<h1>Caught an Exception: " . $@->error . "</h1>";
  } elsif ($@) {
     # if you forget this you'll mask non-exception die()s
     die $@;
  }

That's pretty much exactly what's in the Exception::Class docs.

-sam

---------------------------------------------------------------------
Web Archive:  http://www.mail-archive.com/cgiapp@lists.erlbaum.net/
              http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: cgiapp-unsubscribe@lists.erlbaum.net
For additional commands, e-mail: cgiapp-help@lists.erlbaum.net

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic