|
From: <php...@li...> - 2009-07-03 11:34:21
|
Hi,
There seem to be a bug in runtime exception handling in PHP/Java Bridge 5.4.4.2:
1) Call some java method and get return value successfully
2) Call same method again, but now it throws runtime exception
-> Exception not thrown but returned in php side
Example:
try { $val = $javaObjOrClass->throwIfTrue(true) } catch(Exception $ex) { //catched nicely here }
try { $val = $javaObjOrClass->throwIfTrue(false) } catch(Exception $ex) { //does not come here, $val is ok }
try { $val = $javaObjOrClass->throwIfTrue(true) } catch(Exception $ex) { //does not come here, $val contains exception }
Workaround:
define("JAVA_PREFER_VALUES", true);
Juha
|
|
From: <php...@li...> - 2009-07-03 11:41:39
|
Undeclared exceptions are not handled. This is consistent with other JEE
containers.
[Undeclared]
> Exception not thrown but returned in php side
This is correct behaviour and documented this way.
Regards,
Jost Boekemeier
3. Jul 2009 1:34 nachm. schrieb am <
php...@li...>:
Hi,
There seem to be a bug in runtime exception handling in PHP/Java Bridge
5.4.4.2:
1) Call some java method and get return value successfully
2) Call same method again, but now it throws runtime exception
-> Exception not thrown but returned in php side
Example:
try { $val = $javaObjOrClass->throwIfTrue(true) } catch(Exception $ex) {
//catched nicely here }
try { $val = $javaObjOrClass->throwIfTrue(false) } catch(Exception $ex) {
//does not come here, $val is ok }
try { $val = $javaObjOrClass->throwIfTrue(true) } catch(Exception $ex) {
//does not come here, $val contains exception }
Workaround:
define("JAVA_PREFER_VALUES", true);
Juha
------------------------------------------------------------------------------
_______________________________________________
php-java-bridge-users mailing list
php...@li...
https://lists.sourceforge.net/lists/listinfo/php-java-bridge-users
|
|
From: <php...@li...> - 2009-07-03 12:05:53
|
Ok, but then it is not working consistently. RuntimeException is thrown in first case below, but not in third.
try { $val = $javaObjOrClass->throwIfTrue(true) } catch(Exception $ex) {//catched nicely here }
try { $val = $javaObjOrClass->throwIfTrue(false) } catch(Exception $ex) {//does not come here, $val is ok }
try { $val = $javaObjOrClass->throwIfTrue(true) } catch(Exception $ex) {//does not come here, $val contains exception }
And consistent or not with other containers, I think this makes life much harder on PHP side. To be safe one should do in some cases something like:
try {
$obj = $java->methodA($arg);
$rex = java_values($obj);
if ($rex instanceof Exception)
throw $rex;
$val = $obj->methodB();
...
} catch (Exception $ex) {
// handle exception
}
instead of:
try {
$val = $java->methodA($arg)->methodB();
...
} catch (Exception $ex) {
// handle exception
}
---
Juha
Undeclared exceptions are not handled. This is consistent with other JEE
containers.
[Undeclared]
> Exception not thrown but returned in php side
This is correct behaviour and documented this way.
Regards,
Jost Boekemeier
3. Jul 2009 1:34 nachm. schrieb am <
php...@li...>:
Hi,
There seem to be a bug in runtime exception handling in PHP/Java Bridge
5.4.4.2:
1) Call some java method and get return value successfully
2) Call same method again, but now it throws runtime exception
-> Exception not thrown but returned in php side
Example:
try { $val = $javaObjOrClass->throwIfTrue(true) } catch(Exception $ex) {
//catched nicely here }
try { $val = $javaObjOrClass->throwIfTrue(false) } catch(Exception $ex) {
//does not come here, $val is ok }
try { $val = $javaObjOrClass->throwIfTrue(true) } catch(Exception $ex) {
//does not come here, $val contains exception }
Workaround:
define("JAVA_PREFER_VALUES", true);
Juha
------------------------------------------------------------------------------
_______________________________________________
php-java-bridge-users mailing list
php...@li...
https://lists.sourceforge.net/lists/listinfo/php-java-bridge-users
------------------------------------------------------------------------------
_______________________________________________
php-java-bridge-users mailing list
php...@li...
https://lists.sourceforge.net/lists/listinfo/php-java-bridge-users
|
|
From: <php...@li...> - 2009-07-03 13:06:46
|
May be. But any exception crossing the php/java container must be declared.
Otherwise the behaviour is unspecified.
The problem is that the bridge may "inline" the method call to gain speed.
If you declare that a method doesn't throw an exception and the first method
invocation indeed runs okay, the method is "inlined" and doesn't generate a
round trip anymore.
The option prefer values disables this, making the comm. about 20 times
slower.
Ejb for example has a similar requirement for exceptions crossing the ejb
container (e.g. undeclared RuntimeExceptions immediately kill the current
transaction), I think JEE programmers will not run into this problem.
--Everybody else should read the JavaException API documentation, or they
will learn this the hard way. :)
Regards,
Jost Boekemeier
3. Jul 2009 2:08 nachm. schrieb am <
php...@li...>:
Ok, but then it is not working consistently. RuntimeException is thrown in
first case below, but not in third.
try { $val = $javaObjOrClass->throwIfTrue(true) } catch(Exception $ex)
{//catched nicely here } tr...
And consistent or not with other containers, I think this makes life much
harder on PHP side. To be safe one should do in some cases something like:
try {
$obj = $java->methodA($arg);
$rex = java_values($obj);
if ($rex instanceof Exception)
throw $rex;
$val = $obj->methodB();
...
} catch (Exception $ex) {
// handle exception
}
instead of:
try {
$val = $java->methodA($arg)->methodB();
...
} catch (Exception $ex) {
// handle exception
}
---
Juha
Undeclared exceptions are not handled. This is consistent with other JEE
containers. [Undeclared]...
|
|
From: <php...@li...> - 2009-07-06 05:15:27
|
Hi,
Since PHP/java Bridge version 5.4.4.2.1 any undeclared exception terminates
the script immediately. For example:
try {
echo new java("java.lang.String", null);
} catch (JavaException { ... }
=> PHP Fatal Error: Undeclared RuntimeException: NullPointerException.
I hope this will stop PHP programmers to (ab)use java.lang.RuntimeException
as some kind of "easy to use" application-level exception.
Regards,
Jost Boekemeier
3. Jul 2009 2:08 nachm. schrieb am <
php...@li...>:
Ok, but then it is not working consistently. RuntimeException is thrown in
first case below, but not in third.
try { $val = $javaObjOrClass->throwIfTrue(true) } catch(Exception $ex)
{//catched nicely here } tr...
And consistent or not with other containers, I think this makes life much
harder on PHP side. To be safe one should do in some cases something like:
try {
$obj = $java->methodA($arg);
$rex = java_values($obj);
if ($rex instanceof Exception)
throw $rex;
$val = $obj->methodB();
...
} catch (Exception $ex) {
// handle exception
}
instead of:
try {
$val = $java->methodA($arg)->methodB();
...
} catch (Exception $ex) {
// handle exception
}
---
Juha
Undeclared exceptions are not handled. This is consistent with other JEE
containers. [Undeclared]...
|