logo       
Google Custom Search
    AddThis Social Bookmark Button

Re: Using Exception::Class with Login module: msg#00045

Subject: Re: 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 $@->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@xxxxxxxxxxxxxxxxx/
              http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: cgiapp-unsubscribe@xxxxxxxxxxxxxxxxx
For additional commands, e-mail: cgiapp-help@xxxxxxxxxxxxxxxxx





Try Searching:
servers, voip, java, networking, microsoft ...
<Prev in Thread] Current Thread [Next in Thread>