Class IllegalClassException

  • All Implemented Interfaces:
    java.io.Serializable

    @Deprecated(since="2021-04-30")
    public class IllegalClassException
    extends java.lang.IllegalArgumentException
    Deprecated.
    Commons Lang 2 is in maintenance mode. Commons Lang 3 should be used instead.

    Thrown when an object is an instance of an unexpected type (a class or interface). This exception supplements the standard IllegalArgumentException by providing a more semantically rich description of the problem.

    IllegalClassException represents the case where a method takes in a genericly typed parameter like Object (typically because it has to due to some other interface it implements), but this implementation only actually accepts a specific type, for example String. This exception would be used in place of IllegalArgumentException, yet it still extends it.

      public void foo(Object obj) {
        if (obj instanceof String == false) {
          throw new IllegalClassException(String.class, obj);
        }
        // do something with the string
      }
      
    Since:
    2.0
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      IllegalClassException​(java.lang.Class expected, java.lang.Class actual)
      Deprecated.
      Instantiates with the expected and actual types.
      IllegalClassException​(java.lang.Class expected, java.lang.Object actual)
      Deprecated.
      Instantiates with the expected type, and actual object.
      IllegalClassException​(java.lang.String message)
      Deprecated.
      Instantiates with the specified message.
    • Method Summary

      • Methods inherited from class java.lang.Throwable

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

        equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • IllegalClassException

        public IllegalClassException​(java.lang.Class expected,
                                     java.lang.Object actual)
        Deprecated.

        Instantiates with the expected type, and actual object.

        Parameters:
        expected - the expected type
        actual - the actual object
        Since:
        2.1
      • IllegalClassException

        public IllegalClassException​(java.lang.Class expected,
                                     java.lang.Class actual)
        Deprecated.

        Instantiates with the expected and actual types.

        Parameters:
        expected - the expected type
        actual - the actual type
      • IllegalClassException

        public IllegalClassException​(java.lang.String message)
        Deprecated.

        Instantiates with the specified message.

        Parameters:
        message - the exception message