Practical mod_perl / HTML Book /



previous page: E.3.3. Sending Email
  
page up: HTML Version of the book
  
next page: E.3.5. Utilities Taglib

E.3.4. Handling Exceptions


The exception taglib, AxKit::XSP::Exception, is used to catch exceptions. The syntax is very simple: rather than allowing different types of exceptions, it is currently a very simple try/catch block. To use the exceptions taglib, the following has to be added to httpd.conf:

AxAddXSPTaglib AxKit::XSP::Exception

Then you can implement form validation using exceptions, as Example E-6 demonstrates.

Example E-6. exceptiontaglib.xsp

<xsp:page
 xmlns:xsp="http://apache.org/xsp/core/v1"
 xmlns:param="http://attic.apache.org/projects/axkit.html/NS/xsp/param/v1"
 xmlns:except="http://attic.apache.org/projects/axkit.html/NS/xsp/exception/v1"
 language="Perl"
>
<page>
 # form validation:
 <except:try>
  <xsp:logic>
  if ((<param:number/> > 10) || (0 > <param:number/>)) {
    die "Number must be between 0 and 10";
  }
  if (!<param:name/>) {
    die "You must supply a name";
  }
  # Now do something with the params
  </xsp:logic>
  <p>Values saved successfully!</p>
  <except:catch>
   <p>Sorry, the values you entered were
      incorrect: <except:message/></p>
  </except:catch>
 </except:try>
</page>

The exact same try/catch (and message) tags can be used for sendmail and for ESQL (discussed in a moment).

 

Continue to:

  • prev: E.3.3. Sending Email
  • Table of Contents
  • next: E.3.5. Utilities Taglib







TOP
previous page: E.3.3. Sending Email
  
page up: HTML Version of the book
  
next page: E.3.5. Utilities Taglib


Menu

  • HTML Book
  • PDF Book
  • Download Code
  • Table of Contents
  • Errata
  • mod_perl2 User's Guide
  • Sitemap

Search


Add to Google




Creative Commons License


Written by
Eric Cholet (Logilune) and
Stas Bekman (StasoSphere & Free Books).


[ Privacy Policy | Terms of Use | About Us | Search ]

© 2007 StasoSphere.com