xml-commons-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcnam...@apache.org
Subject cvs commit: xml-commons/java/external/src/javax/xml/transform TransformerException.java
Date Tue, 20 Jul 2004 22:42:45 GMT
mcnamara    2004/07/20 15:42:44

  Modified:    java/external/src/javax/xml/transform Tag: tck-jaxp-1_2_0
                        TransformerException.java
  Log:
  The printStackTrace method of the Throwable class in jdk 1.4
  and higher will include the cause when printing the backtrace.
  
  Patch provided by Joanne Tong.
  Patch reviewed by Henry Zongaro.
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.3.8.3   +50 -37    xml-commons/java/external/src/javax/xml/transform/TransformerException.java
  
  Index: TransformerException.java
  ===================================================================
  RCS file: /home/cvs/xml-commons/java/external/src/javax/xml/transform/TransformerException.java,v
  retrieving revision 1.3.8.2
  retrieving revision 1.3.8.3
  diff -u -r1.3.8.2 -r1.3.8.3
  --- TransformerException.java	1 May 2004 23:07:44 -0000	1.3.8.2
  +++ TransformerException.java	20 Jul 2004 22:42:43 -0000	1.3.8.3
  @@ -311,49 +311,62 @@
               super.printStackTrace(s);
           } catch (Throwable e) {}
   
  -        Throwable exception = getException();
   
  -        for (int i = 0; (i < 10) && (null != exception); i++) {
  -            s.println("---------");
  -
  -            try {
  -                if (exception instanceof TransformerException) {
  -                    String locInfo =
  -                        ((TransformerException) exception)
  -                            .getLocationAsString();
  -
  -                    if (null != locInfo) {
  -                        s.println(locInfo);
  +        boolean isJdk14OrHigher = false;
  +        try {
  +        	Throwable.class.getMethod("getCause",null);
  +        	isJdk14OrHigher = true;
  +        } catch (NoSuchMethodException nsme) {
  +        	// do nothing
  +        }
  +        
  +        // The printStackTrace method of the Throwable class in jdk 1.4 
  +        // and higher will include the cause when printing the backtrace.
  +        // The following code is only required when using jdk 1.3 or lower            
    
  +        if (!isJdk14OrHigher) {
  +            Throwable exception = getException();
  +            for (int i = 0; (i < 10) && (null != exception); i++) {
  +                s.println("---------");
  +            
  +                try {
  +                    if (exception instanceof TransformerException) {
  +                        String locInfo =
  +                            ((TransformerException) exception)
  +                                .getLocationAsString();
  +            
  +                        if (null != locInfo) {
  +                            s.println(locInfo);
  +                        }
                       }
  +            
  +                    exception.printStackTrace(s);
  +                } catch (Throwable e) {
  +                    s.println("Could not print stack trace...");
                   }
  -
  -                exception.printStackTrace(s);
  -            } catch (Throwable e) {
  -                s.println("Could not print stack trace...");
  -            }
  -
  -            try {
  -                Method meth =
  -                    ((Object) exception).getClass().getMethod("getException",
  -                        null);
  -
  -                if (null != meth) {
  -                    Throwable prev = exception;
  -
  -                    exception = (Throwable) meth.invoke(exception, null);
  -
  -                    if (prev == exception) {
  -                        break;
  +            
  +                try {
  +                    Method meth =
  +                        ((Object) exception).getClass().getMethod("getException",
  +                            null);
  +            
  +                    if (null != meth) {
  +                        Throwable prev = exception;
  +            
  +                        exception = (Throwable) meth.invoke(exception, null);
  +            
  +                        if (prev == exception) {
  +                            break;
  +                        }
  +                    } else {
  +                        exception = null;
                       }
  -                } else {
  +                } catch (InvocationTargetException ite) {
  +                    exception = null;
  +                } catch (IllegalAccessException iae) {
  +                    exception = null;
  +                } catch (NoSuchMethodException nsme) {
                       exception = null;
                   }
  -            } catch (InvocationTargetException ite) {
  -                exception = null;
  -            } catch (IllegalAccessException iae) {
  -                exception = null;
  -            } catch (NoSuchMethodException nsme) {
  -                exception = null;
               }
           }
   	s.flush();
  
  
  

Mime
View raw message