View Javadoc

    1   /*
    2    * GroovyCastException.java created on 21.11.2006
    3    *
    4    * To change this generated comment go to
    5    * Window>Preferences>Java>Code Generation>Code and Comments
    6    */
    7   package org.codehaus.groovy.runtime.typehandling;
    8
    9   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, Class classToCastTo) {
    20         String classToCastFrom;
    21         if (objectToCast!=null) {
    22             classToCastFrom = objectToCast.getClass().getName();
    23         } else {
    24             objectToCast = "null";
    25             classToCastFrom = "null";
    26         }
    27         return "Cannot cast object '" + objectToCast + "' " +
    28                "with class '" + classToCastFrom + "' " +
    29                "to class '" + classToCastTo.getName() + "'";
    30      }
    31
    32  }