01: /*
02: * GroovyCastException.java created on 21.11.2006
03: *
04: * To change this generated comment go to
05: * Window>Preferences>Java>Code Generation>Code and Comments
06: */
07: package org.codehaus.groovy.runtime.typehandling;
08:
09: public class GroovyCastException extends ClassCastException {
10:
11: public GroovyCastException(Object objectToCast, Class classToCastTo) {
12: super (makeMessage(objectToCast, classToCastTo));
13: }
14:
15: public GroovyCastException(String string) {
16: super (string);
17: }
18:
19: private static String makeMessage(Object objectToCast,
20: Class classToCastTo) {
21: String classToCastFrom;
22: if (objectToCast != null) {
23: classToCastFrom = objectToCast.getClass().getName();
24: } else {
25: objectToCast = "null";
26: classToCastFrom = "null";
27: }
28: return "Cannot cast object '" + objectToCast + "' "
29: + "with class '" + classToCastFrom + "' "
30: + "to class '" + classToCastTo.getName() + "'";
31: }
32:
33: }
|