logo
Exceptions are important in Java, here's how to throw them:
$class = $turpenv->findClass('java/lang/Exception');
$constructor = $class->findConstructor('(Ljava/lang/String;)V');
$instance = $class->create($constructor, 'Test');
$turpenv->throw($instance);
...
$turpenv->throwNew('java/lang/IllegalArgumentException', 'Test');
We can also check whether an Exception occured:
if ($exc = $turpenv->exceptionOccurred()) {
...
}
and we can catch them:
$turpenv->throwNew('java/lang/IllegalArgumentException', 'Test');
if ($exc = $turpenv->exceptionOccurred()) {
  printf("Msg: %s\n", $exc->toString('()Ljava/lang/String;'));
  $turpenv->exceptionClear();
}
see: ExceptionSample.java

Comments

Add Comment

name:
email:
homepage:
comment:
Please enter the following code into the "verify" field below:
Verify: