On Feb 27, 2008, at 7:31 AM, Tobia Conforto wrote:

Actually XSLTC does preserve the cause, but it's wrapped in TransformerExceptions.

Well if that's the case then Cocoon should show it to you. See ExceptionGenerator [1], it uses ExceptionUtils.getCause(current) to unroll exceptions. If ExceptionUtils.getCause() method does not understand TransformerExceptions, then it should be enhanced.


I managed to solve the issue by patching TraxTransformer so that it removes wrapping exceptions (of SAXException and TransformerException type, arbitrarily nested) before re-throwing the core exception.

That is not the preferred solution; instead, please check why TransformerException is not unrolled by Cocoon's error page.

Vadim


I will leave it to this list to figure out if it's a useful patch to merge in Cocoon.
It certainly makes the XSLTC transformer much more useable.

But maybe there's a better place to put this un-wrapping code?


Tobia


--- transformation/TraxTransformer.orig 2008-02-26 18:28:23.000000000 +0100 +++ transformation/TraxTransformer.java 2008-02-27 13:28:27.000000000 +0100
@@ -29,6 +29,7 @@

import javax.xml.transform.sax.SAXResult;
import javax.xml.transform.sax.TransformerHandler;
+import javax.xml.transform.TransformerException;

import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.configuration.Configurable;
@@ -586,8 +587,21 @@
            super.endDocument();
        } catch(Exception e) {

-            Throwable realEx = this.errorListener.getThrowable();
-            if (realEx == null) realEx = e;
+            Throwable realEx = e;
+            while (true) {
+                if (realEx instanceof SAXException) {
+ Throwable nested = ((SAXException) realEx).getException();
+                    if (nested == null)
+                        break;
+                    realEx = nested;
+                } else if (realEx instanceof TransformerException) {
+ Throwable nested = ((TransformerException) realEx).getException();
+                    if (nested == null)
+                        break;
+                    realEx = nested;
+                } else
+                    break;
+            }

            if (realEx instanceof RuntimeException) {
                throw (RuntimeException)realEx;


Reply via email to