From 65e85a6cc2d74adbd781057354beb9f74ae24a4d Mon Sep 17 00:00:00 2001 From: "igor%mir2.org" Date: Tue, 13 May 2003 10:07:44 +0000 Subject: [PATCH] Replace catch for various exceptions that reflection methods can throw by single catch (Exception ex) to have smaller code. --- .../javascript/JavaScriptException.java | 32 +++++++------------ 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/js/rhino/src/org/mozilla/javascript/JavaScriptException.java b/js/rhino/src/org/mozilla/javascript/JavaScriptException.java index 3f87df8cc587..f87a2347def2 100644 --- a/js/rhino/src/org/mozilla/javascript/JavaScriptException.java +++ b/js/rhino/src/org/mozilla/javascript/JavaScriptException.java @@ -48,23 +48,22 @@ import java.lang.reflect.Method; */ public class JavaScriptException extends Exception { /** - *

Pointer to initCause() method of Throwable. + *

Pointer to initCause() method of Throwable. * If this method does not exist, * (i.e. we're running on something earlier than Java 1.4), the pointer will * be null.

*/ - public static Method initCauseMethod = null; + private static Method initCauseMethod = null; static { // Are we running on a JDK 1.4 or later system? try { - initCauseMethod = Throwable.class.getMethod("initCause", - new Class[]{Throwable.class}); - } catch (NoSuchMethodException nsme) { - // We are not running on JDK 1.4 - } catch (SecurityException se) { - // This should have not happened, but if it does, - // pretend the method odes not exist. + Class ThrowableClass = ScriptRuntime.classOrNull( + "java.lang.Throwable"); + initCauseMethod = ThrowableClass.getMethod("initCause", + new Class[]{ThrowableClass}); + } catch (Exception ex) { + // Assume any exceptions means the method does not exist. } } @@ -77,18 +76,11 @@ public class JavaScriptException extends Exception { */ public JavaScriptException(Object value) { super(ScriptRuntime.toString(value)); - if ((value instanceof Throwable) && (initCauseMethod != null)) { + if (value instanceof Throwable && initCauseMethod != null) { try { - initCauseMethod.invoke(this, new Object[] {(Throwable) value}); - } catch (IllegalAccessException e) { - // we cannot help you here - e.printStackTrace(); // Print the stacktrace to System.err so nice people would know what hit them - } catch (IllegalArgumentException e) { - // Should never happen. - e.printStackTrace(); // Print the stacktrace to System.err so nice people would know what hit them - } catch (InvocationTargetException e) { - // This neither, since initCause() does not throw any exceptions (at least in Java 1.4 it doesn't) - e.printStackTrace(); // Print the stacktrace to System.err so nice people would know what hit them + initCauseMethod.invoke(this, new Object[] {value}); + } catch (Exception e) { + // Ignore any exceptions } } this.value = value;