You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Jens von Pilgrim <j....@4flow.de> on 2002/01/23 12:04:03 UTC

Extensions, Exceptions and Xalan

Hello,

  I've got a problem here with error handling and XSL extensions.
I've written some extensions and I'm wondering how to implement a nice
error handling.

What's the problem in detail? Well...:

Let's take a sample extension function like this:

public static String foo
    (ExpressionContext i_ExprCtxt,String i_strValue) {
  ... do someting ...
  return something;
}

  If "... do something ..." everything is fine, but what happens if an
error occurs, that is if an exception is thrown?
  I only see two possiblities, and I don't like them both:

1) catch all exceptions in foo and return en empty string:

public static String foo
    (ExpressionContext i_ExprCtxt,String i_strValue) {
  try {
    ... do someting ...
    return something;
  } catch (Exception ex) {
    // log error
  }
  return "";
}

Advantage: 
  The transforming process is finished, that is it's robust.

Disadvantage: 
  Even if I can log the error somewhere, it's not using
Xalan's logging mechanism, that is the transformer's ErrorListener is
not used.

2) throw the exception to Xalan:
public static String foo
    (ExpressionContext i_ExprCtxt,String i_strValue) 
	throws Exception {
  ... do someting ...
  return something;
}

Advantage: 
  The exception is catched by Xalan and the ErrorListener is notified.
The ErrorListener can display a message (and e.g. the exception message)
to the
user.

Disadvantage: 
  The transforming process is not finished, a failure in the extension
disables the whole transforming.


  Of course, sometimes the tranforming makes no sense if an extension
function fails. But sometimes the transforming still makes sense, even
if an extension function fails.
  
  The dilemma is that I have to choose a robust, but quiet, solution or
a talking, but not very robust solution.
  Is it possible to throw a "warning" exception or to retrieve the
transformer's ErrorListener in an extension function?

--
Jens von Pilgrim
4flow AG, Berlin, Germany
http://www.4flow.de