comparison core/src/luan/LuanJavaFunction.java @ 210:e84655b4c45e

better exception handling git-svn-id: https://luan-java.googlecode.com/svn/trunk@211 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Tue, 08 Jul 2014 19:05:27 +0000
parents 239c8d650028
children 5b9726553ac8
comparison
equal deleted inserted replaced
209:239c8d650028 210:e84655b4c45e
69 public Class<?>[] getParameterTypes() { 69 public Class<?>[] getParameterTypes() {
70 return method.getParameterTypes(); 70 return method.getParameterTypes();
71 } 71 }
72 72
73 @Override public Object call(LuanState luan,Object[] args) throws LuanException { 73 @Override public Object call(LuanState luan,Object[] args) throws LuanException {
74 args = fixArgs(luan,args);
75 try { 74 try {
75 args = fixArgs(luan,args);
76 return doCall(luan,args); 76 return doCall(luan,args);
77 } catch(IllegalArgumentException e) { 77 } catch(IllegalArgumentException e) {
78 checkArgs(luan,args); 78 checkArgs(luan,args);
79 throw e; 79 throw e;
80 } 80 }
126 if( type.isPrimitive() ) 126 if( type.isPrimitive() )
127 type = primitiveMap.get(type); 127 type = primitiveMap.get(type);
128 Object arg = args[i]; 128 Object arg = args[i];
129 if( !type.isInstance(arg) ) { 129 if( !type.isInstance(arg) ) {
130 String expected = paramType.getSimpleName(); 130 String expected = paramType.getSimpleName();
131 if( i==a.length-1 && method.isVarArgs() )
132 expected = paramType.getComponentType().getSimpleName()+"...";
131 if( arg==null ) { 133 if( arg==null ) {
132 if( paramType.isPrimitive() ) 134 if( paramType.isPrimitive() )
133 throw luan.exception("bad argument #"+(i+1-start)+" ("+expected+" expected, got nil)"); 135 throw luan.exception("bad argument #"+(i+1-start)+" ("+expected+" expected, got nil)");
134 } else { 136 } else {
135 String got = arg.getClass().getSimpleName(); 137 String got = arg.getClass().getSimpleName();