net.protempore.utils
Class BaseRuntimeException

java.lang.Object
  extended by java.lang.Throwable
      extended by java.lang.Exception
          extended by java.lang.RuntimeException
              extended by net.protempore.utils.BaseRuntimeException
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
ValidationException

public class BaseRuntimeException
extends java.lang.RuntimeException

A base runtime exception class that provides 2 additional conveniences: 1) it allows a variable number of arguments to be given in addition to the message, which will be interpolated into the message if there is at least 1; 2) there are overloaded constructors allowing for an array of Throwable instead of just a single Throwable, which is useful when an exception may only be thrown at the end of a method, and multiple underlying exceptions may be the cause of the end exception thrown.

Example: instead of needing to do:

throw new BaseRuntimeException(origExc, "The baz with id '" + id + "' and name '" + name, "' is foo bar.")

you can do the simpler:

throw new BaseRuntimeException(origExc, "The baz with id '%s' and name '%s' is foo bar."), id, name)

In case of an exception occurring while interpolating the message, the original message string will be used and error output will be printed to standard error, since we do not want to introduce a logger dependency by logging the problem.

See Also:
Serialized Form

Constructor Summary
BaseRuntimeException()
          Create a new exception that specifies no message or cause.
BaseRuntimeException(java.util.List<? extends java.lang.Throwable> causes)
          Create a new exception with the given causes.
BaseRuntimeException(java.util.List<? extends java.lang.Throwable> causes, java.lang.String msg, java.lang.Object... args)
          Create new exception with the given error message and causes.
BaseRuntimeException(java.lang.String msg, java.lang.Object... args)
          Create a new exception with the given error message, interpolating the args into the msg string if there are any.
BaseRuntimeException(java.lang.Throwable cause)
          Create a new exception with the given cause.
BaseRuntimeException(java.lang.Throwable cause, java.lang.String msg, java.lang.Object... args)
          Create new exception with the given error message and cause.
 
Method Summary
 java.util.List<? extends java.lang.Throwable> getCauses()
          Get all the underlying causes if any, or else the empty list.
 java.util.List<java.lang.String> getMessages()
          A convenience method that returns a list consisting of this exception's message and the messages of all its causes.
 java.lang.String toString()
          
 
Methods inherited from class java.lang.Throwable
fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BaseRuntimeException

public BaseRuntimeException()
Create a new exception that specifies no message or cause.


BaseRuntimeException

public BaseRuntimeException(java.lang.String msg,
                            java.lang.Object... args)
Create a new exception with the given error message, interpolating the args into the msg string if there are any.

Parameters:
msg - A message.
args - Any number of message arguments (in accordance with msg string).

BaseRuntimeException

public BaseRuntimeException(java.lang.Throwable cause)
Create a new exception with the given cause.

Parameters:
cause - The underlying cause of this exception.

BaseRuntimeException

public BaseRuntimeException(java.util.List<? extends java.lang.Throwable> causes)
Create a new exception with the given causes. The must be at least 1 cause, and the first will be used as the cause that Throwable.getCause() will return. All causes may be retrieved using getCauses().

Parameters:
causes - The underlying causes of this exception.

BaseRuntimeException

public BaseRuntimeException(java.lang.Throwable cause,
                            java.lang.String msg,
                            java.lang.Object... args)
Create new exception with the given error message and cause.

Parameters:
msg - An error message.
args - Any number of message arguments (in accordance with msg string).
cause - The underlying cause of this exception.

BaseRuntimeException

public BaseRuntimeException(java.util.List<? extends java.lang.Throwable> causes,
                            java.lang.String msg,
                            java.lang.Object... args)
Create new exception with the given error message and causes.

Parameters:
causes - The underlying causes of this exception (must be non-null and have at least 1 item).
msg - An error message.
args - Any number of message arguments (in accordance with msg string).
Method Detail

getCauses

public java.util.List<? extends java.lang.Throwable> getCauses()
Get all the underlying causes if any, or else the empty list.

Returns:
The underlying causes.

toString

public java.lang.String toString()

Overrides:
toString in class java.lang.Throwable

getMessages

public java.util.List<java.lang.String> getMessages()
A convenience method that returns a list consisting of this exception's message and the messages of all its causes. The messages of all direct causes of this exception are included, but deeper than that it is just the message of the primary cause that is included (not secondary causes if the exceptions are also instances of BaseRuntimeException with multiple causes).

Returns:
A non-null list containing zero or more localized (if exception class supports localization) messages.