Renaming Context.hrowAsUncheckedException to Context.throwAsScriptRuntimeEx to better reflect its purpose, providing better documentation and making sure it throws only instances of EcmaError and EvaluatorException.

git-svn-id: svn://10.0.0.236/trunk@151415 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
igor%mir2.org
2004-01-16 15:14:25 +00:00
parent 5189a47915
commit 488148ca6f
9 changed files with 30 additions and 33 deletions

View File

@@ -1446,30 +1446,27 @@ public class Context
}
/**
* Convinient method to rethrow the exception as unchecked exception.
* The exception will be wrapped as {@link WrappedException} unless
* it is an instance of {@link EvaluatorExceptions},
* {@link EcmaError} or java.lang.Error which are rethrown as-is.
* <p>
* Instances of java.lang.reflect.InvocationTargetExceptions are treated
* specially. They are unwrapped and throwAsUncheckedException is applied
* recursively to its target.
* Rethrow the exception wrapping it as the script runtime exception.
* Unless the exception is instance of {@link EcmaError} or
* {@link EvaluatorException} it will be wrapped as
* {@link WrappedException}, a subclass of {@link EvaluatorException}.
* The resulting exception object always contains
* source name and line number of script that triggered exception.
* <p>
* This method always throws an exception, its return value is provided
* only for convenience to allow a usage like:
* <pre>
* throw Context.throwAsUncheckedException(ex);
* throw Context.throwAsScriptRuntimeEx(ex);
* </pre>
* to indicate that code after the method is unreachable.
* @throws EvaluatorException
* @throws EcmaError
*/
public static RuntimeException throwAsUncheckedException(Throwable e)
public static RuntimeException throwAsScriptRuntimeEx(Throwable e)
{
while ((e instanceof InvocationTargetException)) {
e = ((InvocationTargetException) e).getTargetException();
}
if (e instanceof Error) {
throw (Error)e;
}
if (e instanceof EvaluatorException) {
throw (EvaluatorException)e;
}

View File

@@ -87,7 +87,7 @@ public class Delegator implements Function {
try {
return (Delegator)this.getClass().newInstance();
} catch (Exception ex) {
throw Context.throwAsUncheckedException(ex);
throw Context.throwAsScriptRuntimeEx(ex);
}
}

View File

@@ -471,7 +471,7 @@ public class FunctionObject extends BaseFunction
try {
result = (Scriptable) member.getDeclaringClass().newInstance();
} catch (Exception ex) {
throw Context.throwAsUncheckedException(ex);
throw Context.throwAsScriptRuntimeEx(ex);
}
result.setPrototype(getClassPrototype());

View File

@@ -255,7 +255,7 @@ public final class JavaAdapter
newInstance(ctorArgs);
return getAdapterSelf(adapterClass, adapter);
} catch (Exception ex) {
throw Context.throwAsUncheckedException(ex);
throw Context.throwAsScriptRuntimeEx(ex);
}
}
@@ -509,7 +509,7 @@ public final class JavaAdapter
try {
master = (IFGlue)glueClass.newInstance();
} catch (Exception ex) {
throw Context.throwAsUncheckedException(ex);
throw Context.throwAsScriptRuntimeEx(ex);
}
int[] argsToConvert = getArgsToConvert(argTypes);
master.ifglue_initMaster(argsToConvert);
@@ -633,7 +633,7 @@ public final class JavaAdapter
try {
return f.call(cx, scope, thisObj, args);
} catch (JavaScriptException ex) {
throw Context.throwAsUncheckedException(ex);
throw Context.throwAsScriptRuntimeEx(ex);
}
}

View File

@@ -102,7 +102,7 @@ class JavaMembers
type = field.getType();
}
} catch (Exception ex) {
throw Context.throwAsUncheckedException(ex);
throw Context.throwAsScriptRuntimeEx(ex);
}
// Need to wrap the object before we return it.
scope = ScriptableObject.getTopLevelScope(scope);
@@ -137,7 +137,7 @@ class JavaMembers
try {
bp.setter.invoke(javaObject, args);
} catch (Exception ex) {
throw Context.throwAsUncheckedException(ex);
throw Context.throwAsScriptRuntimeEx(ex);
}
}
else {

View File

@@ -63,7 +63,7 @@ public final class LazilyLoadedCtor {
ScriptableObject.DONTENUM);
}
catch (PropertyException e) {
throw Context.throwAsUncheckedException(e);
throw Context.throwAsScriptRuntimeEx(e);
}
}
@@ -88,7 +88,7 @@ public final class LazilyLoadedCtor {
} catch (SecurityException ex) {
removeOnError = true;
} catch (Exception e) {
throw Context.throwAsUncheckedException(e);
throw Context.throwAsScriptRuntimeEx(e);
}
}
if (removeOnError) {

View File

@@ -163,7 +163,7 @@ final class MemberBox implements Serializable
try {
return invoker.invoke(target, args);
} catch (Exception ex) {
throw Context.throwAsUncheckedException(ex);
throw Context.throwAsScriptRuntimeEx(ex);
} catch (LinkageError ex) {
invoker = null;
}
@@ -179,16 +179,16 @@ final class MemberBox implements Serializable
method = accessible;
} else {
if (!tryToMakeAccessible(method)) {
throw Context.throwAsUncheckedException(ex);
throw Context.throwAsScriptRuntimeEx(ex);
}
}
// Retry after recovery
return method.invoke(target, args);
}
} catch (IllegalAccessException ex) {
throw Context.throwAsUncheckedException(ex);
throw Context.throwAsScriptRuntimeEx(ex);
} catch (InvocationTargetException ex) {
throw Context.throwAsUncheckedException(ex);
throw Context.throwAsScriptRuntimeEx(ex);
}
}
@@ -200,16 +200,16 @@ final class MemberBox implements Serializable
return ctor.newInstance(args);
} catch (IllegalAccessException ex) {
if (!tryToMakeAccessible(ctor)) {
throw Context.throwAsUncheckedException(ex);
throw Context.throwAsScriptRuntimeEx(ex);
}
}
return ctor.newInstance(args);
} catch (IllegalAccessException ex) {
throw Context.throwAsUncheckedException(ex);
throw Context.throwAsScriptRuntimeEx(ex);
} catch (InvocationTargetException ex) {
throw Context.throwAsUncheckedException(ex);
throw Context.throwAsScriptRuntimeEx(ex);
} catch (InstantiationException ex) {
throw Context.throwAsUncheckedException(ex);
throw Context.throwAsScriptRuntimeEx(ex);
}
}

View File

@@ -691,7 +691,7 @@ WrapFactory#wrap(Context cx, Scriptable scope, Object obj, Class)}
try {
glue = adapter_makeIFGlue.invoke(null, args);
} catch (Exception ex) {
throw Context.throwAsUncheckedException(ex);
throw Context.throwAsScriptRuntimeEx(ex);
}
if (glue != null) {
// Store for later retrival

View File

@@ -96,7 +96,7 @@ public class Codegen extends Interpreter {
onlySave = true;
}
} catch (IOException iox) {
throw Context.throwAsUncheckedException(iox);
throw Context.throwAsScriptRuntimeEx(iox);
}
if (!isPrimary) {
@@ -124,7 +124,7 @@ public class Codegen extends Interpreter {
onlySave = true;
}
} catch (IOException iox) {
throw Context.throwAsUncheckedException(iox);
throw Context.throwAsScriptRuntimeEx(iox);
}
}
}