org.apache.cocoon.util.location
Class LocatedException

java.lang.Object
  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:
ProcessingException

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.

Since:
2.1.8
Version:
$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
delegate
 
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

LocatedException

public LocatedException(String message)

LocatedException

public LocatedException(String message,
                        Throwable cause)

LocatedException

public LocatedException(String message,
                        Location location)

LocatedException

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

ensureCauseChainIsSet

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.


addCauseLocations

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.

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

getLocation

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

Specified by:
getLocation in interface Locatable
Returns:
the location

getLocations

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

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

getRawMessage

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
Returns:
the raw message

getMessage

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.

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

getMessage

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

addLocation

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
Parameters:
loc - the location to be added.


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