public class PortalException extends Exception implements IPortalException
try { // Some code throws exception here ... } catch (Exception exc) { throw new PortalException(exc); }
You may dynmically extend the PortalException by implementing the PortalException.IPortalExceptionDelegate
interface and registering your implementation with the portal.
The PortalException uses the registered delegate each time a new PortalException is constructed. It will invoke the IPortalExceptionDelegate.exceptionThrown function which gives the delegate an opprotunity to replace the original exception with a custom exception.
To register an exception delegate modify the setenv.bat/setenv.sh to have the following line:
set JAVA_OPTIONS=%JAVA_OPTIONS% -DportalException.delegate=your.exception.delegate.class.name
The following is a simple example of an IPortalExceptionDelegate:
import java.sql.SQLException;
public class SampleExceptionDelegate implements PortalException.IPortalExceptionDelegate {
public void initialize() {
}
public Throwable exceptionThrown(String message, Throwable target, PortalException portalException) {
return new CustomException(message, target);
}
public class CustomException extends Exception {
public CustomException(String message, Throwable cause) {
super(message, cause);
}
public String getMessage() {
Throwable t = getCause();
if (t == null) {
return super.getMessage();
}
if (t instanceof SQLException) {
return "SQLException: " + super.getMessage();
}
return "Unknown Exception:" + super.getMessage();
}
}
}
Modifier and Type | Class and Description |
---|---|
static interface |
PortalException.IPortalExceptionDelegate
The PortalException uses the registered delegate each time a new PortalException is constructed.
|
Modifier and Type | Field and Description |
---|---|
protected static String |
CURRENT_ERROR_LIST |
static String |
EXCEPTION_DELEGATE_CLASS_NAME |
protected static Logger |
logger |
protected Object |
m_context |
protected List<Object> |
m_errorList |
protected boolean |
m_ignoreTargetMessage |
protected boolean |
m_isExpected |
protected boolean |
m_isLocalizable |
protected Object[] |
m_messageArgs |
protected IMessageInfo |
m_messageInfo |
protected String |
m_messageKey |
protected Class<? extends ResourceBundle> |
m_resBundleClass |
protected Throwable |
m_target |
protected static PortalException.IPortalExceptionDelegate |
s_portalExceptionDelegate |
Modifier | Constructor and Description |
---|---|
protected |
PortalException()
Deprecated.
|
|
PortalException(Class<? extends ResourceBundle> resourceBundleClass,
String messageKey)
Constructor to create a localized exception message.
|
|
PortalException(Class<? extends ResourceBundle> resourceBundleClass,
String messageKey,
Object[] messageArgs)
Constructor to create a localized bundle.
|
|
PortalException(String message)
Deprecated.
|
|
PortalException(String message,
boolean isExpected)
Deprecated.
|
|
PortalException(String message,
Throwable target)
Deprecated.
|
|
PortalException(String message,
Throwable target,
boolean isExpected)
Deprecated.
|
|
PortalException(Throwable target)
Construct exception instance with nested exception only.
|
|
PortalException(Throwable target,
boolean isExpected)
Constructs exception with nested exception only.
|
|
PortalException(Throwable target,
Class<? extends ResourceBundle> resourceBundleClass,
String messageKey)
Constructor to create a localized exception message.
|
|
PortalException(Throwable target,
Class<? extends ResourceBundle> resourceBundleClass,
String messageKey,
Object[] messageArgs)
Constructor to create a localized bundle.
|
Modifier and Type | Method and Description |
---|---|
static void |
addDetailsMesasge(IMessageInfo messageInfo)
When an exception is about to be thrown, you might want to add an explanatory
message to the exception.
|
static void |
addDetailsMessage(String msg)
Deprecated.
(use the new local specific)
|
protected void |
checkExpected(Throwable thrown)
"inherit" expected flag from the specified exception
|
Throwable |
getCause()
Get the thrown target exception if any was assigned
|
Object |
getContext()
Get context object associated with the exception (if any).
|
List<Object> |
getErrorList()
Return error list reference if any were created.
|
List<Object> |
getErrorList(boolean localize)
Return error list reference if any were created.
|
protected IGlobalProvider |
getGlobalProvider() |
String |
getLocalizedMessage()
Localize the message
|
String |
getMessage()
Returns a message from the exception.
|
String |
getMessageKey() |
Throwable |
getTargetException()
Get the thrown target exception if any was assigned
|
static Object |
getTLS(Object key) |
protected void |
initDetailsMessage()
Initializes details message list.
|
boolean |
isExpected()
Identifies whether particular exception was expected or not.
|
static PortalException |
notImplemented(String methodName)
Allows throwing "not implemented" exception.
|
void |
printFullStackTrace()
Overridden behavior of
Exception . |
void |
printFullStackTrace(PrintWriter s)
Overridden behavior of
Exception . |
void |
printStackTrace()
Overridden behavior of
Exception . |
void |
printStackTrace(PrintStream s)
Overridden behavior of
Exception . |
void |
printStackTrace(PrintWriter s)
Overridden behavior of
Exception . |
static void |
putTLS(Object key,
Object value) |
static void |
removeTLS(Object key) |
static void |
reset()
Resets any error messages.
|
static PortalException |
reuseOrWrapException(Throwable t) |
void |
setContext(Object context)
Assigns context object to provide additional information about
exception (if necessary).
|
void |
setExpected(boolean value)
Specify whether particular exception was expected or not.
|
void |
setIgnoreTargetMessage(boolean value)
Specify whether the exception error message should
ignore the target exception.
|
addSuppressed, fillInStackTrace, getStackTrace, getSuppressed, initCause, setStackTrace, toString
public static final String EXCEPTION_DELEGATE_CLASS_NAME
protected static final String CURRENT_ERROR_LIST
protected Throwable m_target
protected Object m_context
protected boolean m_isExpected
protected boolean m_isLocalizable
protected Class<? extends ResourceBundle> m_resBundleClass
protected String m_messageKey
protected Object[] m_messageArgs
protected boolean m_ignoreTargetMessage
protected transient IMessageInfo m_messageInfo
protected static PortalException.IPortalExceptionDelegate s_portalExceptionDelegate
PortalException.IPortalExceptionDelegate
protected static Logger logger
public PortalException(Throwable target)
target
- Nested exceptionpublic PortalException(Throwable target, boolean isExpected)
target
- Nested exceptionisExpected
- Expected exception flagpublic PortalException(Class<? extends ResourceBundle> resourceBundleClass, String messageKey)
ResourceBundle
will be inferred from the source
paramter
The messageKey will be used to obtain the correct localized messagepublic PortalException(Class<? extends ResourceBundle> resourceBundleClass, String messageKey, Object[] messageArgs)
ResourceBundle
will be inferred from the source
paramter
The messageKey will be used to obtain the correct localized message
The messageArgs will be used to format the messagpublic PortalException(Throwable target, Class<? extends ResourceBundle> resourceBundleClass, String messageKey)
ResourceBundle
will be inferred from the source
paramter
The messageKey will be used to obtain the correct localized messagepublic PortalException(Throwable target, Class<? extends ResourceBundle> resourceBundleClass, String messageKey, Object[] messageArgs)
ResourceBundle
will be inferred from the source
paramter
The messageKey will be used to obtain the correct localized message
The messageArgs will be used to format the messag@Deprecated protected PortalException()
@Deprecated public PortalException(String message, Throwable target, boolean isExpected)
message
- Exception messagetarget
- Nested exceptionisExpected
- Expected exception flag@Deprecated public PortalException(String message)
message
- Exception message@Deprecated public PortalException(String message, boolean isExpected)
message
- Exception messageisExpected
- Expected exception flag@Deprecated public PortalException(String message, Throwable target)
message
- Exception messagetarget
- Nested exceptionpublic Throwable getTargetException()
m_target
public Throwable getCause()
public String getMessage()
getMessage
in class Throwable
public String getMessageKey()
public String getLocalizedMessage()
getLocalizedMessage
in class Throwable
public void printStackTrace(PrintWriter s)
Exception
. Prints stack trace to the
PrintWriter
. Overridden to allow Log4J to correctly print
wrapped exceptions. The trick is that when we have nested exception we should
print its stack trace instead of ours.printStackTrace
in class Throwable
s
- PrintWriter instancepublic void printFullStackTrace(PrintWriter s)
Exception
. Overridden to allow Log4J to
correctly print wrapped exceptions. Uses default writer.s
- PrintWriter instancepublic void printStackTrace(PrintStream s)
Exception
.
Prints stack trace to the PrintStream
. Overridden to
allow Log4J to correctly print wrapped exceptions.printStackTrace
in class Throwable
s
- PrintStream instancepublic void printStackTrace()
Exception
. Overridden to
allow Log4J to correctly print wrapped exceptions. Uses default writer.printStackTrace
in class Throwable
public void printFullStackTrace()
Exception
.
Overridden to allow Log4J to correctly print wrapped exceptions.
Uses default writer.public void setIgnoreTargetMessage(boolean value)
value
- true to ignore the target exception message, false otherwisepublic void setExpected(boolean value)
value
- whether exception is expected or notpublic boolean isExpected()
protected void checkExpected(Throwable thrown)
thrown
- Exception instance to inherit expected flagpublic Object getContext()
public void setContext(Object context)
context
- Context object referencepublic List<Object> getErrorList()
public List<Object> getErrorList(boolean localize)
public static PortalException notImplemented(String methodName)
throw PortalException.notImplemented("SomeObject.someMethod");
methodName
- Signature of the method to be implementedPortalException
to throw furtherpublic static void addDetailsMesasge(IMessageInfo messageInfo)
Unfortunately, you might not be in the code firing the exception, but in the code that clearly understands the details of the exception.
If so, add your message to the exception (to be thrown by you or someone else) with this API.
The constructor of the PortalException will gather these up and expose them with the call:
getErrorList()
messageInfo
- Message to add to error listIMessageInfo
@Deprecated public static void addDetailsMessage(String msg)
Unfortunately, you might not be in the code firing the exception, but in the code that clearly understands the details of the exception.
If so, add your message to the exception (to be thrown by you or someone else) with this API.
The constructor of the PortalException will gather these up and expose them with the call:
getErrorList()
msg
- Message to add to error listpublic static void reset()
addDetailsMessage(java.lang.String)
protected void initDetailsMessage()
protected IGlobalProvider getGlobalProvider()
public static PortalException reuseOrWrapException(Throwable t)
public static void removeTLS(Object key)