CheckstyleException now supports nested exceptions
This commit is contained in:
parent
89488c9d42
commit
eeba08c102
|
|
@ -171,7 +171,7 @@ public class Checker extends AutomaticBean
|
|||
// TODO i18n
|
||||
throw new CheckstyleException(
|
||||
"cannot initialize module "
|
||||
+ name + " - " + ex.getMessage());
|
||||
+ name + " - " + ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -160,17 +160,19 @@ class ConfigurationLoader
|
|||
return loader.getConfiguration();
|
||||
}
|
||||
catch (FileNotFoundException e) {
|
||||
throw new CheckstyleException("unable to find " + aConfigFname);
|
||||
throw new CheckstyleException(
|
||||
"unable to find " + aConfigFname, e);
|
||||
}
|
||||
catch (ParserConfigurationException e) {
|
||||
throw new CheckstyleException("unable to parse " + aConfigFname);
|
||||
throw new CheckstyleException(
|
||||
"unable to parse " + aConfigFname, e);
|
||||
}
|
||||
catch (SAXException e) {
|
||||
throw new CheckstyleException("unable to parse "
|
||||
+ aConfigFname + " - " + e.getMessage());
|
||||
+ aConfigFname + " - " + e.getMessage(), e);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new CheckstyleException("unable to read " + aConfigFname);
|
||||
throw new CheckstyleException("unable to read " + aConfigFname, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -163,7 +163,8 @@ public class PackageNamesLoader
|
|||
reader = new FileReader(aFilename);
|
||||
}
|
||||
catch (FileNotFoundException e) {
|
||||
throw new CheckstyleException("unable to find " + aFilename);
|
||||
throw new CheckstyleException(
|
||||
"unable to find " + aFilename, e);
|
||||
}
|
||||
final InputSource source = new InputSource(reader);
|
||||
return loadModuleFactory(source, aFilename);
|
||||
|
|
@ -186,17 +187,17 @@ public class PackageNamesLoader
|
|||
return nameLoader.getModuleFactory();
|
||||
}
|
||||
catch (FileNotFoundException e) {
|
||||
throw new CheckstyleException("unable to find " + aSourceName);
|
||||
throw new CheckstyleException("unable to find " + aSourceName, e);
|
||||
}
|
||||
catch (ParserConfigurationException e) {
|
||||
throw new CheckstyleException("unable to parse " + aSourceName);
|
||||
throw new CheckstyleException("unable to parse " + aSourceName, e);
|
||||
}
|
||||
catch (SAXException e) {
|
||||
throw new CheckstyleException("unable to parse "
|
||||
+ aSourceName + " - " + e.getMessage());
|
||||
+ aSourceName + " - " + e.getMessage(), e);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new CheckstyleException("unable to read " + aSourceName);
|
||||
throw new CheckstyleException("unable to read " + aSourceName, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -116,15 +116,15 @@ class PackageObjectFactory implements ModuleFactory
|
|||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
throw new CheckstyleException(
|
||||
"Unable to find class for " + aClassName);
|
||||
"Unable to find class for " + aClassName, e);
|
||||
}
|
||||
catch (InstantiationException e) {
|
||||
throw new CheckstyleException(
|
||||
"Unable to instantiate " + aClassName);
|
||||
"Unable to instantiate " + aClassName, e);
|
||||
}
|
||||
catch (IllegalAccessException e) {
|
||||
throw new CheckstyleException(
|
||||
"Unable to instantiate " + aClassName);
|
||||
"Unable to instantiate " + aClassName, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -151,7 +151,7 @@ class PackageObjectFactory implements ModuleFactory
|
|||
}
|
||||
catch (CheckstyleException ex2) {
|
||||
throw new CheckstyleException(
|
||||
"Unable to instantiate " + aName);
|
||||
"Unable to instantiate " + aName, ex2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -295,7 +295,7 @@ public final class TreeWalker
|
|||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
throw new CheckstyleException("illegal token \""
|
||||
+ token + "\" in check " + aCheck);
|
||||
+ token + "\" in check " + aCheck, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -170,27 +170,27 @@ public class AutomaticBean implements Configurable, Contextualizable
|
|||
throw new CheckstyleException(
|
||||
"Cannot set property '" + key + "' in module "
|
||||
+ aConfiguration.getName() + " to '" + value
|
||||
+ "': " + e.getTargetException().getMessage());
|
||||
+ "': " + e.getTargetException().getMessage(), e);
|
||||
}
|
||||
catch (IllegalAccessException e) {
|
||||
throw new CheckstyleException(
|
||||
"cannot access " + key + " in "
|
||||
+ this.getClass().getName());
|
||||
+ this.getClass().getName(), e);
|
||||
}
|
||||
catch (NoSuchMethodException e) {
|
||||
throw new CheckstyleException(
|
||||
"cannot access " + key + " in "
|
||||
+ this.getClass().getName());
|
||||
+ this.getClass().getName(), e);
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
throw new CheckstyleException(
|
||||
"illegal value '" + value + "' for property '" + key
|
||||
+ "' of module " + aConfiguration.getName());
|
||||
+ "' of module " + aConfiguration.getName(), e);
|
||||
}
|
||||
catch (ConversionException e) {
|
||||
throw new CheckstyleException(
|
||||
"illegal value '" + value + "' for property '" + key
|
||||
+ "' of module " + aConfiguration.getName());
|
||||
+ "' of module " + aConfiguration.getName(), e);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -226,22 +226,22 @@ public class AutomaticBean implements Configurable, Contextualizable
|
|||
// + " is not interested in " + value)
|
||||
throw new CheckstyleException("cannot set property "
|
||||
+ key + " to value " + value + " in bean "
|
||||
+ this.getClass().getName());
|
||||
+ this.getClass().getName(), e);
|
||||
}
|
||||
catch (IllegalAccessException e) {
|
||||
throw new CheckstyleException(
|
||||
"cannot access " + key + " in "
|
||||
+ this.getClass().getName());
|
||||
+ this.getClass().getName(), e);
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
throw new CheckstyleException(
|
||||
"illegal value '" + value + "' for property '" + key
|
||||
+ "' of bean " + this.getClass().getName());
|
||||
+ "' of bean " + this.getClass().getName(), e);
|
||||
}
|
||||
catch (ConversionException e) {
|
||||
throw new CheckstyleException(
|
||||
"illegal value '" + value + "' for property '" + key
|
||||
+ "' of bean " + this.getClass().getName());
|
||||
+ "' of bean " + this.getClass().getName(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,9 @@ package com.puppycrawl.tools.checkstyle.api;
|
|||
*/
|
||||
public class CheckstyleException extends Exception
|
||||
{
|
||||
/** the cause of this exception */
|
||||
private Throwable mCause = null;
|
||||
|
||||
/**
|
||||
* Creates a new <code>CheckstyleException</code> instance.
|
||||
*
|
||||
|
|
@ -35,4 +38,48 @@ public class CheckstyleException extends Exception
|
|||
{
|
||||
super(aMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new <code>CheckstyleException</code> instance
|
||||
* that was caused by another exception.
|
||||
*
|
||||
* @param aMessage a message that explains this exception
|
||||
* @param aCause the Exception that is wrapped by this exception
|
||||
*/
|
||||
public CheckstyleException(String aMessage, Throwable aCause)
|
||||
{
|
||||
super(aMessage);
|
||||
initCause(aCause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the cause of this exception.
|
||||
* In JDK 1.4 (and later) the cause is printed as part of
|
||||
* the exception stacktrace.
|
||||
*
|
||||
* @param aCause the exception that caused this
|
||||
* CheckstyleException to be thrown
|
||||
* @return a reference to this CheckstyleException instance
|
||||
*/
|
||||
public synchronized Throwable initCause(Throwable aCause)
|
||||
{
|
||||
if (mCause != null) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
if (mCause == this) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
mCause = aCause;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the cause of this exception, might be <code>null</code>.
|
||||
*/
|
||||
public Throwable getCause()
|
||||
{
|
||||
return mCause;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue