]> granicus.if.org Git - php/commitdiff
Add experimental APIs to get and clear the last exception
authorSam Ruby <rubys@php.net>
Sat, 8 Jul 2000 10:35:50 +0000 (10:35 +0000)
committerSam Ruby <rubys@php.net>
Sat, 8 Jul 2000 10:35:50 +0000 (10:35 +0000)
ext/java/README
ext/java/except.php [new file with mode: 0644]
ext/java/java.c
ext/java/reflect.java
ext/rpc/java/README
ext/rpc/java/except.php [new file with mode: 0644]
ext/rpc/java/java.c
ext/rpc/java/reflect.java

index 6a19f8e95229c8c021fceb6f85e9716e3de36e4d..6c64dcfe400ec069ff6de8e01f6dd04d21a74a21 100644 (file)
@@ -20,7 +20,15 @@ What is PHP4 ext/java?
         the same syntax.  Furthermore, if the java object is of type
         "java.lang.Class", then static members
 
-     4) Exceptions raised result in PHP warnings, and null results.
+     4) Exceptions raised result in PHP warnings, and null results.  The
+        warnings may be eliminated by prefixing the method call with an
+        "@" sign.  The following experimental APIs may be used to retrieve
+        and reset the last error:
+
+          java_last_exception_get()
+          java_last_exception_clear()
+
+        These APIs are not currently implemented in a reentrant fashion.
 
      5) Overload resolution is in general a hard problem given the
         differences in types between the two languages.  The PHP Java
diff --git a/ext/java/except.php b/ext/java/except.php
new file mode 100644 (file)
index 0000000..a7e6a79
--- /dev/null
@@ -0,0 +1,23 @@
+<?
+  $stack=new Java("java.util.Stack");
+  $stack->push(1);
+
+  #
+  # Should succeed and print out "1"
+  #
+  $result = $stack->pop();
+  $ex = java_last_exception_get();
+  if (!$ex) print "$result\n";
+
+  #
+  # Should fail - note the "@" eliminates the warning
+  #
+  $result=@$stack->pop();
+  $ex=java_last_exception_get();
+  if ($ex) print $ex->toString();
+
+  #
+  # Reset last exception
+  #
+  java_last_exception_clear();
+?>
index 10ee1391ce0109cf816ff58a7f4558469a03e98b..9d0cf7516e27c215b5415e4fffa630c98e819cfe 100644 (file)
@@ -384,6 +384,36 @@ void java_call_function_handler
 
 /***************************************************************************/
 
+PHP_FUNCTION(java_last_exception_get)
+{
+  jlong result = 0;
+  jmethodID lastEx;
+
+  (pval*)(long)result = return_value;
+  
+  lastEx = (*jenv)->GetStaticMethodID(jenv, php_reflect, "lastException",
+          "(J)V");
+
+  (*jenv)->CallStaticVoidMethod(jenv, php_reflect, lastEx, result);
+}
+
+/***************************************************************************/
+
+PHP_FUNCTION(java_last_exception_clear)
+{
+  jlong result = 0;
+  jmethodID clearEx;
+
+  (pval*)(long)result = return_value;
+  
+  clearEx = (*jenv)->GetStaticMethodID(jenv, php_reflect, "clearException",
+          "()V");
+
+  (*jenv)->CallStaticVoidMethod(jenv, php_reflect, clearEx);
+}
+
+/***************************************************************************/
+
 static pval _java_getset_property
   (zend_property_reference *property_reference, jobjectArray value)
 {
@@ -475,6 +505,8 @@ PHP_MSHUTDOWN_FUNCTION(java) {
 }
 
 function_entry java_functions[] = {
+  PHP_FE(java_last_exception_get, NULL)
+  PHP_FE(java_last_exception_clear, NULL)
   {NULL, NULL, NULL}
 };
 
index 0d6347cf8414b74e4ef235a9cf119a1c297698b8..35842ea939e140ba6a867cf6d5530432d1fa1505 100644 (file)
@@ -88,12 +88,23 @@ public class reflect {
     }
   }
 
+  static Throwable lastException = null;
+
+  static void lastException(long result) {
+    setResult(result, lastException);
+  }
+
+  static void clearException() {
+    lastException = null;
+  }
+
   static void setException(long result, Throwable e) {
     if (e instanceof InvocationTargetException) {
       Throwable t = ((InvocationTargetException)e).getTargetException();
       if (t!=null) e=t;
     }
 
+    lastException = e;
     setException(result, e.toString().getBytes());
   }
 
index 6a19f8e95229c8c021fceb6f85e9716e3de36e4d..6c64dcfe400ec069ff6de8e01f6dd04d21a74a21 100644 (file)
@@ -20,7 +20,15 @@ What is PHP4 ext/java?
         the same syntax.  Furthermore, if the java object is of type
         "java.lang.Class", then static members
 
-     4) Exceptions raised result in PHP warnings, and null results.
+     4) Exceptions raised result in PHP warnings, and null results.  The
+        warnings may be eliminated by prefixing the method call with an
+        "@" sign.  The following experimental APIs may be used to retrieve
+        and reset the last error:
+
+          java_last_exception_get()
+          java_last_exception_clear()
+
+        These APIs are not currently implemented in a reentrant fashion.
 
      5) Overload resolution is in general a hard problem given the
         differences in types between the two languages.  The PHP Java
diff --git a/ext/rpc/java/except.php b/ext/rpc/java/except.php
new file mode 100644 (file)
index 0000000..a7e6a79
--- /dev/null
@@ -0,0 +1,23 @@
+<?
+  $stack=new Java("java.util.Stack");
+  $stack->push(1);
+
+  #
+  # Should succeed and print out "1"
+  #
+  $result = $stack->pop();
+  $ex = java_last_exception_get();
+  if (!$ex) print "$result\n";
+
+  #
+  # Should fail - note the "@" eliminates the warning
+  #
+  $result=@$stack->pop();
+  $ex=java_last_exception_get();
+  if ($ex) print $ex->toString();
+
+  #
+  # Reset last exception
+  #
+  java_last_exception_clear();
+?>
index 10ee1391ce0109cf816ff58a7f4558469a03e98b..9d0cf7516e27c215b5415e4fffa630c98e819cfe 100644 (file)
@@ -384,6 +384,36 @@ void java_call_function_handler
 
 /***************************************************************************/
 
+PHP_FUNCTION(java_last_exception_get)
+{
+  jlong result = 0;
+  jmethodID lastEx;
+
+  (pval*)(long)result = return_value;
+  
+  lastEx = (*jenv)->GetStaticMethodID(jenv, php_reflect, "lastException",
+          "(J)V");
+
+  (*jenv)->CallStaticVoidMethod(jenv, php_reflect, lastEx, result);
+}
+
+/***************************************************************************/
+
+PHP_FUNCTION(java_last_exception_clear)
+{
+  jlong result = 0;
+  jmethodID clearEx;
+
+  (pval*)(long)result = return_value;
+  
+  clearEx = (*jenv)->GetStaticMethodID(jenv, php_reflect, "clearException",
+          "()V");
+
+  (*jenv)->CallStaticVoidMethod(jenv, php_reflect, clearEx);
+}
+
+/***************************************************************************/
+
 static pval _java_getset_property
   (zend_property_reference *property_reference, jobjectArray value)
 {
@@ -475,6 +505,8 @@ PHP_MSHUTDOWN_FUNCTION(java) {
 }
 
 function_entry java_functions[] = {
+  PHP_FE(java_last_exception_get, NULL)
+  PHP_FE(java_last_exception_clear, NULL)
   {NULL, NULL, NULL}
 };
 
index 0d6347cf8414b74e4ef235a9cf119a1c297698b8..35842ea939e140ba6a867cf6d5530432d1fa1505 100644 (file)
@@ -88,12 +88,23 @@ public class reflect {
     }
   }
 
+  static Throwable lastException = null;
+
+  static void lastException(long result) {
+    setResult(result, lastException);
+  }
+
+  static void clearException() {
+    lastException = null;
+  }
+
   static void setException(long result, Throwable e) {
     if (e instanceof InvocationTargetException) {
       Throwable t = ((InvocationTargetException)e).getTargetException();
       if (t!=null) e=t;
     }
 
+    lastException = e;
     setException(result, e.toString().getBytes());
   }