Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.commons.lang
Class IllegalClassException

    java.lang.Object
      |
      +--java.lang.Throwable
            |
            +--java.lang.Exception
                  |
                  +--java.lang.RuntimeException
                        |
                        +--java.lang.IllegalArgumentException
                              |
                              +--org.apache.commons.lang.IllegalClassException

All Implemented Interfaces:
  Serializable

public class IllegalClassException
extends IllegalArgumentException

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
Version:
  $Id: IllegalClassException.java 437554 2006-08-28 06:21:41Z bayard $
Author:
  Matthew Hawthorne, Gary Gregory, Stephen Colebourne
See Also:
  Serialized Form

Constructor Summary
`IllegalClassException(Class expected, Class actual)` Instantiates with the expected and actual types.
`IllegalClassException(Class expected, Object actual)` Instantiates with the expected type, and actual object.
`IllegalClassException(String message)` Instantiates with the specified message.

Methods inherited from class java.lang.Throwable
`fillInStackTrace, getLocalizedMessage, getMessage, printStackTrace, printStackTrace, printStackTrace, toString`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Constructor Detail

### IllegalClassException

    public IllegalClassException(Class expected,
                                 Object actual)

  Instantiates with the expected type, and actual object.

  Parameters:
    `expected` - the expected type
    `actual` - the actual object
  Since:
    2.1

### IllegalClassException

    public IllegalClassException(Class expected,
                                 Class actual)

  Instantiates with the expected and actual types.

  Parameters:
    `expected` - the expected type
    `actual` - the actual type

### IllegalClassException

    public IllegalClassException(String message)

  Instantiates with the specified message.

  Parameters:
    `message` - the exception message

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2001-2005 - Apache Software Foundation