Class PortableException

  • All Implemented Interfaces:
    java.io.Serializable

    public final class PortableException
    extends java.lang.Exception

    An Exception-implementation that substitutes other Throwables in an error-stack to make their information portable to other JVMs.

    In a client-server system, ClassNotFoundExceptions may occur, if the server throws a throwable and tries to send it to the client, because the class of the throwable or any of its cause-throwables is not available on the client.

    To solve this problem, one may convert the throwable (and all its cause-throwables) to PortableExceptions by a call to convert(Throwable). This method will convert the whole error-stack to PortableExceptions that contain the same semantics, i.e. the message-, cause- and stacktrace-informations are the same.

    The server can exclude classes that need not be converted with a call to excludePortableBaseExceptionFromConversion(Class). This is a global setting and should be done before any exception is to be converted (usually during server startup). Only subclasses of BaseException may be excluded this way.

    Author:
    agz
    See Also:
    Serialized Form
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.Exception convert​(java.lang.Throwable throwable)
      Converts the specified Throwable and all its cause-throwables recursive to PortableExceptions if their class (or one of its super classes) was not excluded from conversion by a previous call to excludePortableBaseExceptionFromConversion(Class).
      static void excludePortableBaseExceptionFromConversion​(java.lang.Class<? extends BaseException> clazz)
      Excludes the specified BaseException-Class and all its subclasses from future conversions.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Throwable

        addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Method Detail

      • excludePortableBaseExceptionFromConversion

        public static void excludePortableBaseExceptionFromConversion​(java.lang.Class<? extends BaseException> clazz)
        Excludes the specified BaseException-Class and all its subclasses from future conversions. Once set this setting can not be revoked. Several calls to this method are additive.

        The specified class must not be null.

        Parameters:
        clazz - BaseException-Class to exclude from conversion
      • convert

        public static java.lang.Exception convert​(java.lang.Throwable throwable)
        Converts the specified Throwable and all its cause-throwables recursive to PortableExceptions if their class (or one of its super classes) was not excluded from conversion by a previous call to excludePortableBaseExceptionFromConversion(Class).

        If the specified throwable is null, the method returns null.

        Parameters:
        throwable - throwable to convert
        Returns:
        converted throwable (may be the same as specified)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Throwable