cvs: php4 /ext/java README except.php java.c reflect.java
| From: | Sam Ruby | Date: | Sat, 08 Jul 2000 10:35:49 +0000 |
| Subject: | cvs: php4 /ext/java README except.php java.c reflect.java | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-663@lists.php.net to get a copy of this message | ||
rubys Sat Jul 8 03:35:49 2000 EDT
Added files:
/php4/ext/java except.php
Modified files:
/php4/ext/java README java.c reflect.java
Log:
Add experimental APIs to get and clear the last exception
Index: php4/ext/java/README
diff -u php4/ext/java/README:1.6 php4/ext/java/README:1.7
--- php4/ext/java/README:1.6 Mon Jul 3 10:34:40 2000
+++ php4/ext/java/README Sat Jul 8 03:35:49 2000
@@ -20,7 +20,15 @@
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
Index: php4/ext/java/java.c
diff -u php4/ext/java/java.c:1.25 php4/ext/java/java.c:1.26
--- php4/ext/java/java.c:1.25 Thu Jun 29 21:48:45 2000
+++ php4/ext/java/java.c Sat Jul 8 03:35:49 2000
@@ -384,6 +384,36 @@
/***************************************************************************/
+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 @@
}
function_entry java_functions[] = {
+ PHP_FE(java_last_exception_get, NULL)
+ PHP_FE(java_last_exception_clear, NULL)
{NULL, NULL, NULL}
};
Index: php4/ext/java/reflect.java
diff -u php4/ext/java/reflect.java:1.11 php4/ext/java/reflect.java:1.12
--- php4/ext/java/reflect.java:1.11 Thu Jun 29 21:48:45 2000
+++ php4/ext/java/reflect.java Sat Jul 8 03:35:49 2000
@@ -88,12 +88,23 @@
}
}
+ 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: php4/ext/java/except.php
+++ php4/ext/java/except.php
<?
$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();
?>