Class LocatedException

  extended by java.lang.Throwable
      extended by java.lang.Exception
          extended by org.apache.commons.lang.exception.NestableException
              extended by org.apache.cocoon.util.location.LocatedException
All Implemented Interfaces:
Serializable, Locatable, LocatableException, MultiLocatable, org.apache.commons.lang.exception.Nestable
Direct Known Subclasses:

public class LocatedException
extends org.apache.commons.lang.exception.NestableException
implements LocatableException, MultiLocatable

A cascading and located Exception. It is also MultiLocatable to easily build stack traces.

$Id: LocatedException.html 1304258 2012-03-23 10:09:27Z ilgrosso $
See Also:
Serialized Form

Field Summary
Fields inherited from class org.apache.commons.lang.exception.NestableException
Constructor Summary
LocatedException(String message)
LocatedException(String message, Location location)
LocatedException(String message, Throwable cause)
LocatedException(String message, Throwable cause, Location location)
Method Summary
static void addCauseLocations(MultiLocatable self, Throwable cause)
          Add to the location stack all locations of an exception chain.
 void addLocation(Location loc)
          Add a location to the current list of locations.
static void ensureCauseChainIsSet(Throwable thr)
          Crawl the cause chain and ensure causes are properly set using "initCause" on JDK >= 1.4.
 Location getLocation()
          Get the location of this object
 List getLocations()
          Return the list of locations.
 String getMessage()
static String getMessage(String message, List locations)
          Standard way of building the message of a LocatableException, as a Java-like stack trace of locations.
 String getRawMessage()
          Get the raw message of the exception (the one used in the constructor)
Methods inherited from class org.apache.commons.lang.exception.NestableException
getCause, getMessage, getMessages, getThrowable, getThrowableCount, getThrowables, indexOfThrowable, indexOfThrowable, printPartialStackTrace, printStackTrace, printStackTrace, printStackTrace
Methods inherited from class java.lang.Throwable
fillInStackTrace, getLocalizedMessage, getStackTrace, initCause, setStackTrace, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

Constructor Detail


public LocatedException(String message)


public LocatedException(String message,
                        Throwable cause)


public LocatedException(String message,
                        Location location)


public LocatedException(String message,
                        Throwable cause,
                        Location location)
Method Detail


public static void ensureCauseChainIsSet(Throwable thr)
Crawl the cause chain and ensure causes are properly set using "initCause" on JDK >= 1.4. This is needed because some exceptions (e.g. SAXException) don't have a getCause() that is used to print stacktraces.


public static void addCauseLocations(MultiLocatable self,
                                     Throwable cause)
Add to the location stack all locations of an exception chain. This allows to have all possible location information in the stacktrace, as some exceptions like SAXParseException don't output their location in printStackTrace().

Traversal of the call chain stops at the first Locatable exception which is supposed to handle the loction of its causes by itself.

This method is static as a convenience for other implementations of locatable exceptions.

self - the current locatable exception
cause - a cause of self


public Location getLocation()
Description copied from interface: Locatable
Get the location of this object

Specified by:
getLocation in interface Locatable
the location


public List getLocations()
Description copied from interface: MultiLocatable
Return the list of locations.

Specified by:
getLocations in interface MultiLocatable
a list of locations, possibly empty but never null.


public String getRawMessage()
Description copied from interface: LocatableException
Get the raw message of the exception (the one used in the constructor)

Specified by:
getRawMessage in interface LocatableException
the raw message


public static String getMessage(String message,
                                List locations)
Standard way of building the message of a LocatableException, as a Java-like stack trace of locations.

message - the exception's message, given by super.getMessage() (can be null)
locations - the location list (can be null)
the message, or null no message and locations were given.


public String getMessage()
Specified by:
getMessage in interface org.apache.commons.lang.exception.Nestable
getMessage in class org.apache.commons.lang.exception.NestableException


public void addLocation(Location loc)
Description copied from interface: MultiLocatable
Add a location to the current list of locations.

Implementations are free to filter locations that can be added (e.g. Location.UNKNOWN), and there is therefore no guarantee that the given location will actually be added to the list. Filtered locations are silently ignored.

Specified by:
addLocation in interface MultiLocatable
loc - the location to be added.

Copyright © 1999-2010 The Apache Software Foundation. All Rights Reserved.