|
From: <php...@li...> - 2008-05-08 21:22:46
|
To all:
I'm using:
php bridge: 5.1.2
java: jdk1.6.0_02
php: 5.2.5
Here's my question i'm trying to figure out the best way to deal with
errors from the php side throw from java.
Here's an example:
Java:
public class Test{
public Test(String yippie) Throws Exception
{
if(yippie)
{
ex = new Exception("This is an exception thrown from java");
System.out.println("Exception: " + ex.getMessage());
throw ex;
}
}
}
PHP:
try{
$email_address_obj = new Java("type.Test", $email_address);
return $email_address_obj;
} catch (JavaException $ex)
{
echo "Cause: ".$ex->getCause()."\n";
echo "Message: ".(string) $ex->getMessage()."\n";
}
Trouble:
My issue is, I want to out the message Exception was instantiated
with ("This is an exception thrown from java"). However, the
Throwable::getMessage() method is not giving me anything on the php
side, but it is giving me what I want on the java side. Conversely,
the Throwable::getCause() is giving me exactly what is expected.
Any thoughts or help would be greatly appreciated!
Cheers,
Zach
__________________
Gulo Solutions
http://blog.gulosolutions.com
773.276.8066
|
|
From: <php...@li...> - 2008-05-10 19:39:36
|
Hi,
> My issue is, I want to out the message Exception was instantiated
what do you mean with this? $exception->getCause() contains all information you need.
You could coerce the JavaException to that it prints a stack trace which is compatible with other
PHP exceptions, but this shouldn't be default, I think.
Nicht vergessen! Am Sonntag, den 11. Mai ist Muttertag
Geschenkideen, Gedichte & mehr: www.yahoo.de/muttertag
|
|
From: <php...@li...> - 2008-05-12 15:03:59
|
Wow, that was a pretty poorly written sentence. Sorry about that.
What I intended to say was, I was to get the Throwable::getMessage()
from the php side. We'd like to be able to use that for some user
level messaging. That method is giving us what we expect on the Java
side, however, something seems to be lost in the php bridge
translation.
Throwable::getCause() is giving us what we would expect (see below):
PHP:
try{
$email_address_obj = new Java("type.Test", $email_address);
return $email_address_obj;
} catch (JavaException $ex)
{
echo "Cause: ".$ex->getCause()."\n"; // displaying a result
echo "Message: ".(string) $ex->getMessage()."\n"; // not displaying result
}
Thanks,
Zach
__________________
Gulo Solutions
http://blog.gulosolutions.com
773.276.8066
-----Original Message-----
From: php...@li... <php...@li...>
To: php...@li...
Date: Saturday, May 10, 2008, 2:38:31 PM
Subject: [Php-java-bridge-users] Handling Exceptions thrown from java on php side...
Hi,
> My issue is, I want to out the message Exception was instantiated
what do you mean with this? $exception->getCause() contains all information you need.
You could coerce the JavaException to that it prints a stack trace which is compatible with other
PHP exceptions, but this shouldn't be default, I think.
Nicht vergessen! Am Sonntag, den 11. Mai ist Muttertag
Geschenkideen, Gedichte & mehr: www.yahoo.de/muttertag
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
php-java-bridge-users mailing list
php...@li...
https://lists.sourceforge.net/lists/listinfo/php-java-bridge-users
--
No virus found in this incoming message.
Checked by AVG.
Version: 7.5.524 / Virus Database: 269.23.16/1427 - Release Date: 5/11/2008 1:08 PM
|
|
From: <php...@li...> - 2008-05-16 15:51:20
|
Hi,
[please excuse the delay]
> What I intended to say was, I was to get the
> Throwable::getMessage()
> from the php side. We'd like to be able to use that
> for some user
> level messaging. That method is giving us what we expect
> on the Java
> side, however, something seems to be lost in the php bridge
> translation.
It isn't lost. It's just stores the information in the cause.
Isn't it possible to delegate to the throwable which caused the exception? You need to write your own JavaException factory within your product, but this shouldn't be too hard to do. For example (in pseudo code):
class my_JavaExceptionProxy extends JavaException {
function $result;
function my_JavaExceptionProxy ($result) { $this->result = $result; }
function getMessage() {
return $this->result->getCause()->getMessage();
}
}
class my_ThrowExceptionProxyFactory extends java_ThrowExceptionProxyFactory {
function checkResult($result) {
throw new my_JavaException($result);
}
}
In your product:
require_once("java/Java.inc");
// set our own Java exception factory
$client = __java_client->getClient();
$client->throwExceptionProxyFactory =
new my_ThrowExceptionProxyFactory($client);
Regards,
Jost Boekemeier
__________________________________________________________
Gesendet von Yahoo! Mail.
Dem pfiffigeren Posteingang.
http://de.overview.mail.yahoo.com
|
|
From: <php...@li...> - 2008-05-17 02:11:29
|
Thanks for your reply. We still can see the cause and the
"getMessage()" in the cause, however, when we go to access the method
directly, we get nothing.
Here's where we're at now:
**note, we tried to override Java_Exception_Proxy::getMessage()
directly, we received:
[16-May-2008 20:55:17] PHP Fatal error: Cannot override final method
Exception::getMessage() in .../java_exception_proxy.obj
classes implemented:
class Java_Exception_Proxy extends JavaException {
private $result;
public function __construct($result) { $this->result = $result; }
public function getExceptionMessage() {
return $this->result->getCause()->getMessage();
}
}
class Throw_Exception_Proxy_Factory extends java_ThrowExceptionProxyFactory {
public function checkResult($result) {
throw new Java_Exception_Proxy($result);
}
}
product side:
require_once("java/Java.inc");
$jbc=__javaproxy_Client_getClient();
$jbc->throwExceptionProxyFactory = new Throw_Exception_Proxy_Factory($jbc);
try {
// in types.EmailAddress we're throwing a message:
// throw new Exception("Sorry, your email address must contain a '@'.");
$email = new Java("types.EmailAddress", $_POST['email']);
} catch (Java_Exception_Proxy $ex) {
// this gives us empty-ness or empty string
echo $ex->getExceptionMessage();
}
Thanks,
Zach
__________________
Gulo Solutions
http://blog.gulosolutions.com
773.276.8066
-----Original Message-----
From: php...@li... <php...@li...>
To: php...@li...
Date: Friday, May 16, 2008, 10:41:52 AM
Subject: [Php-java-bridge-users] Handling Exceptions thrown from java on php side...
Hi,
[please excuse the delay]
> What I intended to say was, I was to get the
> Throwable::getMessage()
> from the php side. We'd like to be able to use that
> for some user
> level messaging. That method is giving us what we expect
> on the Java
> side, however, something seems to be lost in the php bridge
> translation.
It isn't lost. It's just stores the information in the cause.
Isn't it possible to delegate to the throwable which caused the exception? You need to write your own JavaException factory within your product, but this shouldn't be too hard to do. For example (in pseudo code):
class my_JavaExceptionProxy extends JavaException {
function $result;
function my_JavaExceptionProxy ($result) { $this->result = $result; }
function getMessage() {
return $this->result->getCause()->getMessage();
}
}
class my_ThrowExceptionProxyFactory extends java_ThrowExceptionProxyFactory {
function checkResult($result) {
throw new my_JavaException($result);
}
}
In your product:
require_once("java/Java.inc");
// set our own Java exception factory
$client = __java_client->getClient();
$client->throwExceptionProxyFactory =
new my_ThrowExceptionProxyFactory($client);
Regards,
Jost Boekemeier
__________________________________________________________
Gesendet von Yahoo! Mail.
Dem pfiffigeren Posteingang.
http://de.overview.mail.yahoo.com
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
php-java-bridge-users mailing list
php...@li...
https://lists.sourceforge.net/lists/listinfo/php-java-bridge-users
--
No virus found in this incoming message.
Checked by AVG.
Version: 7.5.524 / Virus Database: 269.23.16/1445 - Release Date: 5/15/2008 7:25 PM
|
|
From: <php...@li...> - 2008-05-18 11:31:21
|
Hi,
> "getMessage()" in the cause, however, when we go
> to access the method
> directly, we get nothing.
that's because PHP's Exception::getMessage() shadows java.lang.Throwable.getMessage().
Please either use getLocalizedMessage() or access "message" directly (which invokes the Java Bean getter "getMessage") or pass the Java message to PHP's exception constructor.
> **note, we tried to override
> Java_Exception_Proxy::getMessage()
> directly, we received:
>
> [16-May-2008 20:55:17] PHP Fatal error: Cannot override
> final method
> Exception::getMessage() in .../java_exception_proxy.obj
That's why the bridge did not provide a resonable default for it.
However, if you extend from Exception, you can access the $message property directly. The following code creates a new Exception and fills PHP's exception property with the exception obtained from Java:
<?php
require_once("java/Java.inc");
class my_JavaException extends java_InternalException {
function __construct ($proxy, $message) {
$this->message = $message;
parent::__construct($proxy->__delegate);
}
}
class my_ThrowExceptionProxyFactory extends java_ThrowExceptionProxyFactory {
function checkResult($result) {
throw new my_JavaException ($result, $result->getCause()->message);
}
}
$client = __javaproxy_Client_getClient();
$client->throwExceptionProxyFactory =
new my_ThrowExceptionProxyFactory($client);
// test
java_autoload("/home/jost/Test.jar");
try {
$test = new Test(true);
} catch (Exception $e) {
echo $e->getMessage();
}
Regards,
Jost Boekemeier
__________________________________________________________
Gesendet von Yahoo! Mail.
Dem pfiffigeren Posteingang.
http://de.overview.mail.yahoo.com
|