[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [cgiapp] Using Exception::Class with Login module


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 suppressed>isa('MyException')) {
     return "<h1>Caught an Exception: " . suppressed>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/suppressed/
              http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: suppressed
For additional commands, e-mail: suppressed


Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.