Example 16-1: Action handler that catches and handles exceptions

import oracle.xml.xsql.*;
import java.util.Date;
import java.text.SimpleDateFormat;
import org.w3c.dom.Node;

public class JavaDate extends XSQLActionHandlerImpl {
  public void handleAction( Node root ) {
    // Get the value of the mask attribute
    String mask = this.getAttributeAllowingParam("mask",getActionElement());
    String dateValue = null;
    if (mask != null && !mask.equals("")) {
      // If we have a non-empty mask, use SimpleDateFormat to format the date
      SimpleDateFormat sdf = new SimpleDateFormat(mask);
      try {
        dateValue = sdf.format(new Date()).toString();
      }
      catch (IllegalArgumentException iax) {
        // If we catch an error, report it
        reportError(root,mask+" is not a valid date format mask");
        return;
      }
    }
    else {
      // Otherwise, just use Date's default string format
      dateValue = (new Date()).toString();
    }
    // Add a <CurrentDate> element to the result with the date value
    addResultElement(root,"CurrentDate",dateValue);
  }
}