Package 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:
java.io.Serializable
public class IllegalClassException extends java.lang.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 ofIllegalArgumentException
, 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 905636 2010-02-02 14:03:32Z niallp $
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private static long
serialVersionUID
Required for serialization support.
-
Constructor Summary
Constructors Constructor Description IllegalClassException(java.lang.Class expected, java.lang.Class actual)
Instantiates with the expected and actual types.IllegalClassException(java.lang.Class expected, java.lang.Object actual)
Instantiates with the expected type, and actual object.IllegalClassException(java.lang.String message)
Instantiates with the specified message.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static java.lang.String
safeGetClassName(java.lang.Class cls)
Returns the class name ornull
if the class isnull
.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
Required for serialization support.- See Also:
Serializable
, Constant Field Values
-
-
Constructor Detail
-
IllegalClassException
public IllegalClassException(java.lang.Class expected, java.lang.Object actual)
Instantiates with the expected type, and actual object.
- Parameters:
expected
- the expected typeactual
- the actual object- Since:
- 2.1
-
IllegalClassException
public IllegalClassException(java.lang.Class expected, java.lang.Class actual)
Instantiates with the expected and actual types.
- Parameters:
expected
- the expected typeactual
- the actual type
-
IllegalClassException
public IllegalClassException(java.lang.String message)
Instantiates with the specified message.
- Parameters:
message
- the exception message
-
-