Class PortalException

java.lang.Object
java.lang.Throwable
java.lang.Exception
com.webmethods.portal.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

public class PortalException extends Exception implements IPortalException
Basic class for all exceptions thrown inside the portal framework. This class supports "nested exceptions" concept, i.e. portal exceptions can wrap other thrown exceptions - this allows the system to propagate the execution stack trace, facilitating debugging.

 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();
        }
    }
}

 
 
See Also:
  • Field Details

  • Constructor Details

    • PortalException

      public PortalException(Throwable target)
      Construct exception instance with nested exception only.
      Parameters:
      target - Nested exception
    • PortalException

      public PortalException(Throwable target, boolean isExpected)
      Constructs exception with nested exception only.
      Parameters:
      target - Nested exception
      isExpected - Expected exception flag
    • PortalException

      public PortalException(Class<? extends ResourceBundle> resourceBundleClass, String messageKey)
      Constructor to create a localized exception message. The ResourceBundle will be inferred from the source 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. The 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
    • PortalException

      public PortalException(Throwable target, Class<? extends ResourceBundle> resourceBundleClass, String messageKey)
      Constructor to create a localized exception message. The ResourceBundle will be inferred from the source 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. The 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
    • PortalException

      @Deprecated protected PortalException()
      Deprecated.
      Default constructor without any parameters.
    • PortalException

      @Deprecated public PortalException(String message, Throwable target, boolean isExpected)
      Deprecated.
      Constructs an exception instance with a target exception and detailed message.
      Parameters:
      message - Exception message
      target - Nested exception
      isExpected - Expected exception flag
    • PortalException

      @Deprecated public PortalException(String message)
      Deprecated.
      Construct exception with message only.
      Parameters:
      message - Exception message
    • PortalException

      @Deprecated public PortalException(String message, boolean isExpected)
      Deprecated.
      Constructor that takes a detail message and expected flag
      Parameters:
      message - Exception message
      isExpected - Expected exception flag
    • PortalException

      @Deprecated public PortalException(String message, Throwable target)
      Deprecated.
      Constructs exception instance with target exception and detail message. Inherits nested exception expected capability
      Parameters:
      message - Exception message
      target - Nested exception
  • Method Details

    • getTargetException

      public Throwable getTargetException()
      Get the thrown target exception if any was assigned
      Returns:
      Nested exception if any assigned
      See Also:
    • getCause

      public Throwable getCause()
      Get the thrown target exception if any was assigned
      Overrides:
      getCause in class Throwable
      Returns:
      Nested exception if any assigned
      See Also:
    • getMessage

      public String getMessage()
      Returns a message from the exception. If target (wrapped) exception was specified then its message is returned.
      Overrides:
      getMessage in class Throwable
      Returns:
      Exception message
    • getMessageKey

      public String getMessageKey()
    • getLocalizedMessage

      public String getLocalizedMessage()
      Localize the message
      Overrides:
      getLocalizedMessage in class Throwable
    • printStackTrace

      public void printStackTrace(PrintWriter s)
      Overridden behavior of 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.
      Overrides:
      printStackTrace in class Throwable
      Parameters:
      s - PrintWriter instance
    • printFullStackTrace

      public void printFullStackTrace(PrintWriter s)
      Overridden behavior of Exception. Overridden to allow Log4J to correctly print wrapped exceptions. Uses default writer.
      Parameters:
      s - PrintWriter instance
    • printStackTrace

      public void printStackTrace(PrintStream s)
      Overridden behavior of Exception. Prints stack trace to the PrintStream. Overridden to allow Log4J to correctly print wrapped exceptions.
      Overrides:
      printStackTrace in class Throwable
      Parameters:
      s - PrintStream instance
    • printStackTrace

      public void printStackTrace()
      Overridden behavior of Exception. Overridden to allow Log4J to correctly print wrapped exceptions. Uses default writer.
      Overrides:
      printStackTrace in class Throwable
    • printFullStackTrace

      public void printFullStackTrace()
      Overridden behavior of Exception. 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

      protected void checkExpected(Throwable thrown)
      "inherit" expected flag from the specified exception
      Parameters:
      thrown - Exception instance to inherit expected flag
    • getContext

      public Object getContext()
      Get context object associated with the exception (if any).
      Returns:
      context object
    • setContext

      public void setContext(Object context)
      Assigns context object to provide additional information about exception (if necessary).
      Parameters:
      context - Context object reference
    • getErrorList

      public List<Object> getErrorList()
      Return error list reference if any were created.
      Returns:
      errors list, or empty list if none created
    • getErrorList

      public List<Object> getErrorList(boolean localize)
      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

      public static PortalException notImplemented(String methodName)
      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

      public static void addDetailsMesasge(IMessageInfo messageInfo)
      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 public static void addDetailsMessage(String msg)
      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

      protected IGlobalProvider getGlobalProvider()
    • reuseOrWrapException

      public static PortalException reuseOrWrapException(Throwable t)
    • putTLS

      public static void putTLS(Object key, Object value)
    • getTLS

      public static Object getTLS(Object key)
    • removeTLS

      public static void removeTLS(Object key)