public final class Errors extends Object
This class also includes a number of methods to turn various classes of exceptions and locators into XML.
Modifier and Type | Method and Description |
---|---|
static String |
cleanMessage(Throwable ex)
Returns a clean message for the specified throwable.
|
static String |
getStackTrace(Throwable error,
boolean safe)
Returns the stack trace of the specified error as a string.
|
static void |
toXML(Exception ex,
org.pageseeder.xmlwriter.XMLWriter xml)
Writes the XML for the given exception.
|
static void |
toXML(Locator locator,
org.pageseeder.xmlwriter.XMLWriter xml)
Returns the specified locator as XML.
|
static void |
toXML(SAXParseException ex,
org.pageseeder.xmlwriter.XMLWriter xml)
Returns the specified exception as XML.
|
static void |
toXML(SourceLocator locator,
org.pageseeder.xmlwriter.XMLWriter xml)
Returns the specified source locator as XML.
|
static void |
toXML(Throwable ex,
org.pageseeder.xmlwriter.XMLWriter xml,
boolean wrap)
Returns the specified exception as XML.
|
static void |
toXML(TransformerException ex,
org.pageseeder.xmlwriter.XMLWriter xml)
Returns the specified exception as XML.
|
public static String getStackTrace(Throwable error, boolean safe)
For security, this method will remove the part of the stacktrace which are specific to the servlet container.
error
- The throwable.safe
- true
to only include the StackTrace up to the servlet API;
false
to include the complete stack trace.public static String cleanMessage(Throwable ex)
This method can be used to provide more user-friendly messages by removing the exception class prefix to the message if the message is identical to that of the exception causing it.
ex
- the throwable.public static void toXML(Exception ex, org.pageseeder.xmlwriter.XMLWriter xml) throws IOException
If there is a more specialised method for this exception defined in this class, this method will automatically use the more specific method.
The default XML for a generic exception is:
The XML return will be:
<exception class="[class]">
<message>[message]</message>
<stack-trace>[exception]</stack-trace>
<cause>[cause exception as XML (if any)]</cause>
</exception>
ex
- The exception to turn to XML.xml
- The XML writer.IOException
- Only if thrown by the XML writer.public static void toXML(Throwable ex, org.pageseeder.xmlwriter.XMLWriter xml, boolean wrap) throws IOException
ex
- The exception to turn to XML.xml
- The XML writer.wrap
- Whether to wrap the XML into an element.IOException
- Only if thrown by the XML writer.public static void toXML(SAXParseException ex, org.pageseeder.xmlwriter.XMLWriter xml) throws IOException
The XML for a SAXParseException
is:
<exception class="[class]" type="SAXParseException">
<message>[message]</message>
<stack-trace>[exception]</stack-trace>
<cause>[cause exception as XML (if any)]</cause>
<location line="[line]" column="[column]" public-id=[public-id]" system-id="[system-id]"/>
</exception>
ex
- The exception to turn to XML.xml
- The XML writer.IOException
- Only if thrown by the XML writer.public static void toXML(TransformerException ex, org.pageseeder.xmlwriter.XMLWriter xml) throws IOException
The XML for a TransformerException
is:
<exception class="[class]" type="[TransformerException|TransformerConfigException]">
<message>[message]</message>
<stack-trace>[exception]</stack-trace>
<cause>[cause exception as XML (if any)]</cause>
<location line="[line]" column="[column]" public-id=[public-id]" system-id="[system-id]"/>
</exception>
ex
- The exception to turn to XML.xml
- The XML writer.IOException
- Only if thrown by the XML writer.public static void toXML(SourceLocator locator, org.pageseeder.xmlwriter.XMLWriter xml) throws IOException
Does nothing if the locator is null
.
The XML return will be:
<location line="[line]" column="[column]" public-id=[public-id]" system-id="[system-id]"/>
locator
- The source locator.xml
- The XML writer.IOException
- Only if thrown by the XML writer.public static void toXML(Locator locator, org.pageseeder.xmlwriter.XMLWriter xml) throws IOException
Does nothing if the locator is null
.
The XML return will be:
<location line="[line]" column="[column]" public-id=[public-id]" system-id="[system-id]"/>
locator
- The source locator.xml
- The XML writer.IOException
- Only if thrown by the XML writer.Copyright © 2016 Allette Systems. All rights reserved.