Class PortalException
- All Implemented Interfaces:
IPortalException
,Serializable
- Direct Known Subclasses:
AuthenticationException
,BasePropertyEditorException
,BizException
,CacheException
,ClusterLockFailedException
,FrameworkException
,InitializationException
,InstallationFailedException
,ISystemPasswordComplexityPolicy.InvalidPasswordException
,MetaException
,PortalAccessException
,RtlException
,TaskLockFailedException
,UnsatisfiedComponentDependencyException
,VersionException
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();
}
}
}
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
The PortalException uses the registered delegate each time a new PortalException is constructed. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final String
static final String
protected static org.slf4j.Logger
protected Object
protected boolean
protected boolean
protected boolean
protected Object[]
protected IMessageInfo
protected String
protected Class<? extends ResourceBundle>
protected Throwable
protected static PortalException.IPortalExceptionDelegate
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
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. -
Method Summary
Modifier and TypeMethodDescriptionstatic 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 exceptiongetCause()
Get the thrown target exception if any was assignedGet context object associated with the exception (if any).Return error list reference if any were created.getErrorList
(boolean localize) Return error list reference if any were created.protected IGlobalProvider
Localize the messageReturns a message from the exception.Get the thrown target exception if any was assignedstatic Object
protected void
Initializes details message list.boolean
Identifies whether particular exception was expected or not.static PortalException
notImplemented
(String methodName) Allows throwing "not implemented" exception.void
Overridden behavior ofException
.void
Overridden behavior ofException
.void
Overridden behavior ofException
.void
Overridden behavior ofException
.void
Overridden behavior ofException
.static void
static void
static void
reset()
Resets any error messages.static PortalException
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.Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getStackTrace, getSuppressed, initCause, setStackTrace, toString
-
Field Details
-
EXCEPTION_DELEGATE_CLASS_NAME
- See Also:
-
CURRENT_ERROR_LIST
- See Also:
-
m_target
-
m_context
-
m_errorList
-
m_isExpected
protected boolean m_isExpected -
m_isLocalizable
protected boolean m_isLocalizable -
m_resBundleClass
-
m_messageKey
-
m_messageArgs
-
m_ignoreTargetMessage
protected boolean m_ignoreTargetMessage -
m_messageInfo
-
s_portalExceptionDelegate
- See Also:
-
logger
protected static org.slf4j.Logger logger
-
-
Constructor Details
-
PortalException
Construct exception instance with nested exception only.- Parameters:
target
- Nested exception
-
PortalException
Constructs exception with nested exception only.- Parameters:
target
- Nested exceptionisExpected
- Expected exception flag
-
PortalException
Constructor to create a localized exception message. TheResourceBundle
will be inferred from thesource
paramter The messageKey will be used to obtain the correct localized message -
PortalException
public PortalException(Class<? extends ResourceBundle> resourceBundleClass, String messageKey, Object[] messageArgs) Constructor to create a localized bundle. TheResourceBundle
will be inferred from thesource
paramter The messageKey will be used to obtain the correct localized message The messageArgs will be used to format the messag -
PortalException
public PortalException(Throwable target, Class<? extends ResourceBundle> resourceBundleClass, String messageKey) Constructor to create a localized exception message. TheResourceBundle
will be inferred from thesource
paramter The messageKey will be used to obtain the correct localized message -
PortalException
public PortalException(Throwable target, Class<? extends ResourceBundle> resourceBundleClass, String messageKey, Object[] messageArgs) Constructor to create a localized bundle. TheResourceBundle
will be inferred from thesource
paramter The messageKey will be used to obtain the correct localized message The messageArgs will be used to format the messag -
PortalException
Deprecated.Default constructor without any parameters. -
PortalException
Deprecated.Constructs an exception instance with a target exception and detailed message.- Parameters:
message
- Exception messagetarget
- Nested exceptionisExpected
- Expected exception flag
-
PortalException
Deprecated.Construct exception with message only.- Parameters:
message
- Exception message
-
PortalException
Deprecated.Constructor that takes a detail message and expected flag- Parameters:
message
- Exception messageisExpected
- Expected exception flag
-
PortalException
Deprecated.Constructs exception instance with target exception and detail message. Inherits nested exception expected capability- Parameters:
message
- Exception messagetarget
- Nested exception
-
-
Method Details
-
getTargetException
Get the thrown target exception if any was assigned- Returns:
- Nested exception if any assigned
- See Also:
-
getCause
Get the thrown target exception if any was assigned -
getMessage
Returns a message from the exception. If target (wrapped) exception was specified then its message is returned.- Overrides:
getMessage
in classThrowable
- Returns:
- Exception message
-
getMessageKey
-
getLocalizedMessage
Localize the message- Overrides:
getLocalizedMessage
in classThrowable
-
printStackTrace
Overridden behavior ofException
. Prints stack trace to thePrintWriter
. 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.- Overrides:
printStackTrace
in classThrowable
- Parameters:
s
- PrintWriter instance
-
printFullStackTrace
Overridden behavior ofException
. Overridden to allow Log4J to correctly print wrapped exceptions. Uses default writer.- Parameters:
s
- PrintWriter instance
-
printStackTrace
Overridden behavior ofException
. Prints stack trace to thePrintStream
. Overridden to allow Log4J to correctly print wrapped exceptions.- Overrides:
printStackTrace
in classThrowable
- Parameters:
s
- PrintStream instance
-
printStackTrace
public void printStackTrace()Overridden behavior ofException
. Overridden to allow Log4J to correctly print wrapped exceptions. Uses default writer.- Overrides:
printStackTrace
in classThrowable
-
printFullStackTrace
public void printFullStackTrace()Overridden behavior ofException
. Overridden to allow Log4J to correctly print wrapped exceptions. Uses default writer. -
setIgnoreTargetMessage
public void setIgnoreTargetMessage(boolean value) Specify whether the exception error message should ignore the target exception.- Parameters:
value
- true to ignore the target exception message, false otherwise
-
setExpected
public void setExpected(boolean value) Specify whether particular exception was expected or not.- Parameters:
value
- whether exception is expected or not
-
isExpected
public boolean isExpected()Identifies whether particular exception was expected or not.- Returns:
- whether this exception instance was expected or not
-
checkExpected
"inherit" expected flag from the specified exception- Parameters:
thrown
- Exception instance to inherit expected flag
-
getContext
Get context object associated with the exception (if any).- Returns:
- context object
-
setContext
Assigns context object to provide additional information about exception (if necessary).- Parameters:
context
- Context object reference
-
getErrorList
Return error list reference if any were created.- Returns:
- errors list, or empty list if none created
-
getErrorList
Return error list reference if any were created. If localize is true, then any message info's will be localized as well- Returns:
- errors list, or empty list if none created
-
notImplemented
Allows throwing "not implemented" exception.throw PortalException.notImplemented("SomeObject.someMethod");
- Parameters:
methodName
- Signature of the method to be implemented- Returns:
- Instance of the
PortalException
to throw further
-
addDetailsMesasge
When an exception is about to be thrown, you might want to add an explanatory message to the exception.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()
- Parameters:
messageInfo
- Message to add to error list- See Also:
-
addDetailsMessage
Deprecated.(use the new local specific)When an exception is about to be thrown, you might want to add an explanatory message to the exception.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()
- Parameters:
msg
- Message to add to error list
-
reset
public static void reset()Resets any error messages.- See Also:
-
initDetailsMessage
protected void initDetailsMessage()Initializes details message list. -
getGlobalProvider
-
reuseOrWrapException
-
putTLS
-
getTLS
-
removeTLS
-