001 002 package railo.runtime.exp; 003 004 import railo.runtime.op.Caster; 005 import railo.runtime.type.util.Type; 006 007 008 /** 009 * 010 */ 011 public class CasterException extends ExpressionException { 012 013 /** 014 * constructor of the Exception 015 * @param o 016 * @param type 017 */ 018 public CasterException(Object o,String type) { 019 super(createMessage(o, type),createDetail(o)); 020 } 021 022 public CasterException(Object o,Class clazz) { 023 super(createMessage(o, clazz.getName()),createDetail(o)); 024 } 025 026 /** 027 * constructor of the Exception 028 * @param message 029 */ 030 public CasterException(String message) { 031 super(message); 032 } 033 034 private static String createDetail(Object o) { 035 if(o!=null) return "Java type of the object is "+Caster.toClassName(o); 036 return "value is null"; 037 } 038 039 public static String createMessage(Object o, String type) { 040 041 if(o instanceof String) return "Can't cast String ["+o+"] to a value of type ["+type+"]"; 042 if(o!=null) return "Can't cast Object type ["+Type.getName(o)+"] to a value of type ["+type+"]"; 043 return "Can't cast Null value to value of type ["+type+"]"; 044 } 045 }