From 4f8bb2ee77ac387500caffe5b3b830547b465bd2 Mon Sep 17 00:00:00 2001 From: Conor MacNeill Date: Sun, 18 Jun 2000 02:22:23 +0000 Subject: [PATCH] Better reporting of errors when JAXP not present. Catch NoClassDefFoundError as well as NullPointerException and emit a more meaningful error message. Change BuildException to accept Errors as well as Exceptions as cause. Submitted by: Stefan Bodewig git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@267682 13f79535-47bb-0310-9956-ffa450edef68 --- src/main/org/apache/tools/ant/BuildException.java | 12 ++++++------ src/main/org/apache/tools/ant/Main.java | 9 +++++++-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/main/org/apache/tools/ant/BuildException.java b/src/main/org/apache/tools/ant/BuildException.java index aa04cc609..ee74c0d0b 100644 --- a/src/main/org/apache/tools/ant/BuildException.java +++ b/src/main/org/apache/tools/ant/BuildException.java @@ -63,7 +63,7 @@ package org.apache.tools.ant; public class BuildException extends RuntimeException { /** Exception that might have caused this one. */ - private Exception cause; + private Throwable cause; /** Location in the build file where the exception occured */ private Location location = Location.UNKNOWN_LOCATION; @@ -89,10 +89,10 @@ public class BuildException extends RuntimeException { * Constructs an exception with the given message and exception as * a root cause. * @param msg Description of or information about the exception. - * @param cause Exception that might have cause this one. + * @param cause Throwable that might have cause this one. */ - public BuildException(String msg, Exception cause) { + public BuildException(String msg, Throwable cause) { super(msg); this.cause = cause; } @@ -105,7 +105,7 @@ public class BuildException extends RuntimeException { * @param location Location in the project file where the error occured. */ - public BuildException(String msg, Exception cause, Location location) { + public BuildException(String msg, Throwable cause, Location location) { this(msg, cause); this.location = location; } @@ -115,7 +115,7 @@ public class BuildException extends RuntimeException { * @param cause Exception that might have caused this one. */ - public BuildException(Exception cause) { + public BuildException(Throwable cause) { super(cause.toString()); this.cause = cause; } @@ -135,7 +135,7 @@ public class BuildException extends RuntimeException { /** * Returns the nested exception. */ - public Exception getException() { + public Throwable getException() { return cause; } diff --git a/src/main/org/apache/tools/ant/Main.java b/src/main/org/apache/tools/ant/Main.java index 42706bfda..b8b8621ed 100644 --- a/src/main/org/apache/tools/ant/Main.java +++ b/src/main/org/apache/tools/ant/Main.java @@ -222,12 +222,17 @@ public class Main { try { try { Class.forName("javax.xml.parsers.SAXParserFactory"); + ProjectHelper.configureProject(project, buildFile); + } catch (NoClassDefFoundError ncdfe) { + throw new BuildException("No JAXP compliant XML parser found. See http://java.sun.com/xml for the\nreference implementation.", ncdfe); } catch (ClassNotFoundException cnfe) { - throw new BuildException(cnfe); + throw new BuildException("No JAXP compliant XML parser found. See http://java.sun.com/xml for the\nreference implementation.", cnfe); + } catch (NullPointerException npe) { + throw new BuildException("No JAXP compliant XML parser found. See http://java.sun.com/xml for the\nreference implementation.", npe); } - ProjectHelper.configureProject(project, buildFile); } catch (BuildException be) { System.out.println("\nBUILD CONFIG ERROR\n"); + System.out.println(be.getMessage()); if (be.getException() == null) { System.out.println(be.toString()); } else {