Java Doc for ExceptionUtils.java in  » Library » Apache-common-lang » org » apache » commons » lang » exception » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Library » Apache common lang » org.apache.commons.lang.exception 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.apache.commons.lang.exception.ExceptionUtils

ExceptionUtils
public class ExceptionUtils (Code)

Provides utilities for manipulating and examining Throwable objects.


author:
   Daniel Rall
author:
   Dmitri Plotnikov
author:
   Stephen Colebourne
author:
   Gary Gregory
author:
   Pete Gieser
since:
   1.0
version:
   $Id: ExceptionUtils.java 437554 2006-08-28 06:21:41Z bayard $


Field Summary
final static  StringWRAPPED_MARKER
    

Constructor Summary
public  ExceptionUtils()
    

Public constructor allows an instance of ExceptionUtils to be created, although that is not normally necessary.


Method Summary
public static  voidaddCauseMethodName(String methodName)
    
public static  ThrowablegetCause(Throwable throwable)
    

Introspects the Throwable to obtain the cause.

The method searches for methods with specific names that return a Throwable object.

public static  ThrowablegetCause(Throwable throwable, String[] methodNames)
    

Introspects the Throwable to obtain the cause.

  1. Try known exception types.
  2. Try the supplied array of method names.
  3. Try the field 'detail'.

A null set of method names means use the default set.

public static  StringgetFullStackTrace(Throwable throwable)
    
public static  StringgetMessage(Throwable th)
     Gets a short message summarising the exception.
public static  ThrowablegetRootCause(Throwable throwable)
    

Introspects the Throwable to obtain the root cause.

This method walks through the exception chain to the last element, "root" of the tree, using ExceptionUtils.getCause(Throwable) , and returns that exception.

From version 2.2, this method handles recursive cause structures that might otherwise cause infinite loops.

public static  StringgetRootCauseMessage(Throwable th)
     Gets a short message summarising the root cause exception.
public static  String[]getRootCauseStackTrace(Throwable throwable)
    

Creates a compact stack trace for the root cause of the supplied Throwable.

The output of this method is consistent across JDK versions. It consists of the root exception followed by each of its wrapping exceptions separated by '[wrapped]'.

static  ListgetStackFrameList(Throwable t)
    

Produces a List of stack frames - the message is not included.

public static  String[]getStackFrames(Throwable throwable)
    

Captures the stack trace associated with the specified Throwable object, decomposing it into a list of stack frames.

The result of this method vary by JDK version as this method uses Throwable.printStackTrace(java.io.PrintWriter) .

static  String[]getStackFrames(String stackTrace)
    
public static  StringgetStackTrace(Throwable throwable)
    

Gets the stack trace from a Throwable as a String.

The result of this method vary by JDK version as this method uses Throwable.printStackTrace(java.io.PrintWriter) .

public static  intgetThrowableCount(Throwable throwable)
    

Counts the number of Throwable objects in the exception chain.

A throwable without cause will return 1. A throwable with one cause will return 2 and so on. A null throwable will return 0.

From version 2.2, this method handles recursive cause structures that might otherwise cause infinite loops.

public static  ListgetThrowableList(Throwable throwable)
    

Returns the list of Throwable objects in the exception chain.

A throwable without cause will return a list containing one element - the input throwable. A throwable with one cause will return a list containing two elements.

public static  Throwable[]getThrowables(Throwable throwable)
    

Returns the list of Throwable objects in the exception chain.

A throwable without cause will return an array containing one element - the input throwable. A throwable with one cause will return an array containing two elements.

public static  intindexOfThrowable(Throwable throwable, Class clazz)
    

Returns the (zero based) index of the first Throwable that matches the specified class (exactly) in the exception chain.

public static  intindexOfThrowable(Throwable throwable, Class clazz, int fromIndex)
    

Returns the (zero based) index of the first Throwable that matches the specified type in the exception chain from a specified index.

public static  intindexOfType(Throwable throwable, Class type)
    

Returns the (zero based) index of the first Throwable that matches the specified class or subclass in the exception chain.

public static  intindexOfType(Throwable throwable, Class type, int fromIndex)
    

Returns the (zero based) index of the first Throwable that matches the specified type in the exception chain from a specified index.

public static  booleanisCauseMethodName(String methodName)
    

Tests if the list of method names used in the search for Throwable objects include the given name.


Parameters:
  methodName - the methodName to search in the list.
public static  booleanisNestedThrowable(Throwable throwable)
    
public static  booleanisThrowableNested()
    
public static  voidprintRootCauseStackTrace(Throwable throwable)
    

Prints a compact stack trace for the root cause of a throwable to System.err.

The compact stack trace starts with the root cause and prints stack frames up to the place where it was caught and wrapped.

public static  voidprintRootCauseStackTrace(Throwable throwable, PrintStream stream)
    

Prints a compact stack trace for the root cause of a throwable.

The compact stack trace starts with the root cause and prints stack frames up to the place where it was caught and wrapped.

public static  voidprintRootCauseStackTrace(Throwable throwable, PrintWriter writer)
    

Prints a compact stack trace for the root cause of a throwable.

The compact stack trace starts with the root cause and prints stack frames up to the place where it was caught and wrapped.

public static  voidremoveCauseMethodName(String methodName)
    
public static  voidremoveCommonFrames(List causeFrames, List wrapperFrames)
    
public static  booleansetCause(Throwable target, Throwable cause)
    

Field Detail
WRAPPED_MARKER
final static String WRAPPED_MARKER(Code)

Used when printing stack frames to denote the start of a wrapped exception.

Package private for accessibility by test suite.





Constructor Detail
ExceptionUtils
public ExceptionUtils()(Code)

Public constructor allows an instance of ExceptionUtils to be created, although that is not normally necessary.





Method Detail
addCauseMethodName
public static void addCauseMethodName(String methodName)(Code)

Adds to the list of method names used in the search for Throwable objects.


Parameters:
  methodName - the methodName to add to the list, nulland empty strings are ignored
since:
   2.0



getCause
public static Throwable getCause(Throwable throwable)(Code)

Introspects the Throwable to obtain the cause.

The method searches for methods with specific names that return a Throwable object. This will pick up most wrapping exceptions, including those from JDK 1.4, and org.apache.commons.lang.exception.NestableException NestableException . The method names can be added to using ExceptionUtils.addCauseMethodName(String) .

The default list searched for are:

  • getCause()
  • getNextException()
  • getTargetException()
  • getException()
  • getSourceException()
  • getRootCause()
  • getCausedByException()
  • getNested()

In the absence of any such method, the object is inspected for a detail field assignable to a Throwable.

If none of the above is found, returns null.


Parameters:
  throwable - the throwable to introspect for a cause, may be null the cause of the Throwable,null if none found or null throwable input
since:
   1.0



getCause
public static Throwable getCause(Throwable throwable, String[] methodNames)(Code)

Introspects the Throwable to obtain the cause.

  1. Try known exception types.
  2. Try the supplied array of method names.
  3. Try the field 'detail'.

A null set of method names means use the default set. A null in the set of method names will be ignored.


Parameters:
  throwable - the throwable to introspect for a cause, may be null
Parameters:
  methodNames - the method names, null treated as default set the cause of the Throwable,null if none found or null throwable input
since:
   1.0



getFullStackTrace
public static String getFullStackTrace(Throwable throwable)(Code)

A way to get the entire nested stack-trace of an throwable.

The result of this method is highly dependent on the JDK version and whether the exceptions override printStackTrace or not.


Parameters:
  throwable - the Throwable to be examined the nested stack trace, with the root cause first
since:
   2.0



getMessage
public static String getMessage(Throwable th)(Code)
Gets a short message summarising the exception.

The message returned is of the form {ClassNameWithoutPackage}: {ThrowableMessage}
Parameters:
  th - the throwable to get a message for, null returns empty string the message, non-null
since:
   Commons Lang 2.2




getRootCause
public static Throwable getRootCause(Throwable throwable)(Code)

Introspects the Throwable to obtain the root cause.

This method walks through the exception chain to the last element, "root" of the tree, using ExceptionUtils.getCause(Throwable) , and returns that exception.

From version 2.2, this method handles recursive cause structures that might otherwise cause infinite loops. If the throwable parameter has a cause of itself, then null will be returned. If the throwable parameter cause chain loops, the last element in the chain before the loop is returned.


Parameters:
  throwable - the throwable to get the root cause for, may be null the root cause of the Throwable,null if none found or null throwable input



getRootCauseMessage
public static String getRootCauseMessage(Throwable th)(Code)
Gets a short message summarising the root cause exception.

The message returned is of the form {ClassNameWithoutPackage}: {ThrowableMessage}
Parameters:
  th - the throwable to get a message for, null returns empty string the message, non-null
since:
   Commons Lang 2.2




getRootCauseStackTrace
public static String[] getRootCauseStackTrace(Throwable throwable)(Code)

Creates a compact stack trace for the root cause of the supplied Throwable.

The output of this method is consistent across JDK versions. It consists of the root exception followed by each of its wrapping exceptions separated by '[wrapped]'. Note that this is the opposite order to the JDK1.4 display.


Parameters:
  throwable - the throwable to examine, may be null an array of stack trace frames, never null
since:
   2.0



getStackFrameList
static List getStackFrameList(Throwable t)(Code)

Produces a List of stack frames - the message is not included. Only the trace of the specified exception is returned, any caused by trace is stripped.

This works in most cases - it will only fail if the exception message contains a line that starts with: "   at".


Parameters:
  t - is any throwable List of stack frames



getStackFrames
public static String[] getStackFrames(Throwable throwable)(Code)

Captures the stack trace associated with the specified Throwable object, decomposing it into a list of stack frames.

The result of this method vary by JDK version as this method uses Throwable.printStackTrace(java.io.PrintWriter) . On JDK1.3 and earlier, the cause exception will not be shown unless the specified throwable alters printStackTrace.


Parameters:
  throwable - the Throwable to examine, may be null an array of strings describing each stack frame, never null



getStackFrames
static String[] getStackFrames(String stackTrace)(Code)

Returns an array where each element is a line from the argument.

The end of line is determined by the value of SystemUtils.LINE_SEPARATOR .

Functionality shared between the getStackFrames(Throwable) methods of this and the org.apache.commons.lang.exception.NestableDelegate classes.


Parameters:
  stackTrace - a stack trace String an array where each element is a line from the argument



getStackTrace
public static String getStackTrace(Throwable throwable)(Code)

Gets the stack trace from a Throwable as a String.

The result of this method vary by JDK version as this method uses Throwable.printStackTrace(java.io.PrintWriter) . On JDK1.3 and earlier, the cause exception will not be shown unless the specified throwable alters printStackTrace.


Parameters:
  throwable - the Throwable to be examined the stack trace as generated by the exception'sprintStackTrace(PrintWriter) method



getThrowableCount
public static int getThrowableCount(Throwable throwable)(Code)

Counts the number of Throwable objects in the exception chain.

A throwable without cause will return 1. A throwable with one cause will return 2 and so on. A null throwable will return 0.

From version 2.2, this method handles recursive cause structures that might otherwise cause infinite loops. The cause chain is processed until the end is reached, or until the next item in the chain is already in the result set.


Parameters:
  throwable - the throwable to inspect, may be null the count of throwables, zero if null input



getThrowableList
public static List getThrowableList(Throwable throwable)(Code)

Returns the list of Throwable objects in the exception chain.

A throwable without cause will return a list containing one element - the input throwable. A throwable with one cause will return a list containing two elements. - the input throwable and the cause throwable. A null throwable will return a list of size zero.

This method handles recursive cause structures that might otherwise cause infinite loops. The cause chain is processed until the end is reached, or until the next item in the chain is already in the result set.


Parameters:
  throwable - the throwable to inspect, may be null the list of throwables, never null
since:
   Commons Lang 2.2



getThrowables
public static Throwable[] getThrowables(Throwable throwable)(Code)

Returns the list of Throwable objects in the exception chain.

A throwable without cause will return an array containing one element - the input throwable. A throwable with one cause will return an array containing two elements. - the input throwable and the cause throwable. A null throwable will return an array of size zero.

From version 2.2, this method handles recursive cause structures that might otherwise cause infinite loops. The cause chain is processed until the end is reached, or until the next item in the chain is already in the result set.


See Also:   ExceptionUtils.getThrowableList(Throwable)
Parameters:
  throwable - the throwable to inspect, may be null the array of throwables, never null



indexOfThrowable
public static int indexOfThrowable(Throwable throwable, Class clazz)(Code)

Returns the (zero based) index of the first Throwable that matches the specified class (exactly) in the exception chain. Subclasses of the specified class do not match - see ExceptionUtils.indexOfType(Throwable,Class) for the opposite.

A null throwable returns -1. A null type returns -1. No match in the chain returns -1.


Parameters:
  throwable - the throwable to inspect, may be null
Parameters:
  clazz - the class to search for, subclasses do not match, null returns -1 the index into the throwable chain, -1 if no match or null input



indexOfThrowable
public static int indexOfThrowable(Throwable throwable, Class clazz, int fromIndex)(Code)

Returns the (zero based) index of the first Throwable that matches the specified type in the exception chain from a specified index. Subclasses of the specified class do not match - see ExceptionUtils.indexOfType(Throwable,Class,int) for the opposite.

A null throwable returns -1. A null type returns -1. No match in the chain returns -1. A negative start index is treated as zero. A start index greater than the number of throwables returns -1.


Parameters:
  throwable - the throwable to inspect, may be null
Parameters:
  clazz - the class to search for, subclasses do not match, null returns -1
Parameters:
  fromIndex - the (zero based) index of the starting position,negative treated as zero, larger than chain size returns -1 the index into the throwable chain, -1 if no match or null input



indexOfType
public static int indexOfType(Throwable throwable, Class type)(Code)

Returns the (zero based) index of the first Throwable that matches the specified class or subclass in the exception chain. Subclasses of the specified class do match - see ExceptionUtils.indexOfThrowable(Throwable,Class) for the opposite.

A null throwable returns -1. A null type returns -1. No match in the chain returns -1.


Parameters:
  throwable - the throwable to inspect, may be null
Parameters:
  type - the type to search for, subclasses match, null returns -1 the index into the throwable chain, -1 if no match or null input
since:
   2.1



indexOfType
public static int indexOfType(Throwable throwable, Class type, int fromIndex)(Code)

Returns the (zero based) index of the first Throwable that matches the specified type in the exception chain from a specified index. Subclasses of the specified class do match - see ExceptionUtils.indexOfThrowable(Throwable,Class) for the opposite.

A null throwable returns -1. A null type returns -1. No match in the chain returns -1. A negative start index is treated as zero. A start index greater than the number of throwables returns -1.


Parameters:
  throwable - the throwable to inspect, may be null
Parameters:
  type - the type to search for, subclasses match, null returns -1
Parameters:
  fromIndex - the (zero based) index of the starting position,negative treated as zero, larger than chain size returns -1 the index into the throwable chain, -1 if no match or null input
since:
   2.1



isCauseMethodName
public static boolean isCauseMethodName(String methodName)(Code)

Tests if the list of method names used in the search for Throwable objects include the given name.


Parameters:
  methodName - the methodName to search in the list. if the list of method names used in the search for Throwableobjects include the given name.
since:
   2.1



isNestedThrowable
public static boolean isNestedThrowable(Throwable throwable)(Code)

Checks whether this Throwable class can store a cause.

This method does not check whether it actually does store a cause.


Parameters:
  throwable - the Throwable to examine, may be null boolean true if nested otherwise false
since:
   2.0




isThrowableNested
public static boolean isThrowableNested()(Code)

Checks if the Throwable class has a getCause method.

This is true for JDK 1.4 and above.

true if Throwable is nestable
since:
   2.0



printRootCauseStackTrace
public static void printRootCauseStackTrace(Throwable throwable)(Code)

Prints a compact stack trace for the root cause of a throwable to System.err.

The compact stack trace starts with the root cause and prints stack frames up to the place where it was caught and wrapped. Then it prints the wrapped exception and continues with stack frames until the wrapper exception is caught and wrapped again, etc.

The output of this method is consistent across JDK versions. Note that this is the opposite order to the JDK1.4 display.

The method is equivalent to printStackTrace for throwables that don't have nested causes.


Parameters:
  throwable - the throwable to output
since:
   2.0



printRootCauseStackTrace
public static void printRootCauseStackTrace(Throwable throwable, PrintStream stream)(Code)

Prints a compact stack trace for the root cause of a throwable.

The compact stack trace starts with the root cause and prints stack frames up to the place where it was caught and wrapped. Then it prints the wrapped exception and continues with stack frames until the wrapper exception is caught and wrapped again, etc.

The output of this method is consistent across JDK versions. Note that this is the opposite order to the JDK1.4 display.

The method is equivalent to printStackTrace for throwables that don't have nested causes.


Parameters:
  throwable - the throwable to output, may be null
Parameters:
  stream - the stream to output to, may not be null
throws:
  IllegalArgumentException - if the stream is null
since:
   2.0



printRootCauseStackTrace
public static void printRootCauseStackTrace(Throwable throwable, PrintWriter writer)(Code)

Prints a compact stack trace for the root cause of a throwable.

The compact stack trace starts with the root cause and prints stack frames up to the place where it was caught and wrapped. Then it prints the wrapped exception and continues with stack frames until the wrapper exception is caught and wrapped again, etc.

The output of this method is consistent across JDK versions. Note that this is the opposite order to the JDK1.4 display.

The method is equivalent to printStackTrace for throwables that don't have nested causes.


Parameters:
  throwable - the throwable to output, may be null
Parameters:
  writer - the writer to output to, may not be null
throws:
  IllegalArgumentException - if the writer is null
since:
   2.0



removeCauseMethodName
public static void removeCauseMethodName(String methodName)(Code)

Removes from the list of method names used in the search for Throwable objects.


Parameters:
  methodName - the methodName to remove from the list, nulland empty strings are ignored
since:
   2.1



removeCommonFrames
public static void removeCommonFrames(List causeFrames, List wrapperFrames)(Code)

Removes common frames from the cause trace given the two stack traces.


Parameters:
  causeFrames - stack trace of a cause throwable
Parameters:
  wrapperFrames - stack trace of a wrapper throwable
throws:
  IllegalArgumentException - if either argument is null
since:
   2.0



setCause
public static boolean setCause(Throwable target, Throwable cause)(Code)

Sets the cause of a Throwable using introspection, allowing source code compatibility between pre-1.4 and post-1.4 Java releases.

The typical use of this method is inside a constructor as in the following example:

 import org.apache.commons.lang.exception.ExceptionUtils;
 public class MyException extends Exception {
 public MyException(String msg) {
 super(msg);
 }
 public MyException(String msg, Throwable cause) {
 super(msg);
 ExceptionUtils.setCause(this, cause);
 }
 }
 

Parameters:
  target - the target Throwable
Parameters:
  cause - the Throwable to set in the target a true if the target has been modified
since:
   2.2



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.