When a Java object fires an event, it may expect the callback script to throw an exception to indicate certain conditions. This can be done using the java::throw command. For example: the vetoableChange event requires the callback script to throw a java.beans.PropertyVetoException if the script deems the new value of a property unaccecptable, as in the following code fragment:
java::bind $b vetoableChange {
if {[java::event propertyName] == "size"} {
if {[java::event newValue] > 10} {
java::throw [java::new java.beans.PropertyVetoException \
"value too large" [java::event]]
}
}
}
The callback script can throw any unchecked exception object (e.g., instances of java.lang.Error or java.lang.RuntimeException.) The callback script can also throw any checked exception allowed by the signature of the event method.
If the callback script throws a checked exception which is not allowed for the event, a Tcl background error is generated. If the callback script is expected to return a value, an undefined value is returned to the Java object.
Copyright © 1997-1998 Sun Microsystems, Inc.