UpdateHandlerException

User 870ab5b546

26-07-2007 17:50:45

We are using the UpdateHandler.execute() method. When the molecule it is trying to put in the database is empty, it throws an UpdateHandlerException.





Code:
chemaxon.jchem.db.UpdateHandlerException: Empty structure


        at chemaxon.jchem.db.UpdateHandler.readMolecule(UpdateHandler.java:1089)


        at chemaxon.jchem.db.UpdateHandler.init(UpdateHandler.java:945)


        at chemaxon.jchem.db.UpdateHandler.execute(UpdateHandler.java:2003)


        at com.prenhall.epoch.db.chem.MolTable.importMol(MolTable.java:146)






However, if I put in a catch statement to catch the UpdateHandlerException, when I try to compile, the Java compiler tells me that an UpdateHandlerException is not thrown in the body of the try:





Code:
javac -deprecation  -Xlint:all -d /home/aceorg/aceorg/DEV-1.7/epoch-plugin/build -classpath /home/aceorg/aceorg/DEV-1.7/epoch-plugin/build:/home/aceorg/aceorg/jchem/lib/jchem.jar:/home/aceorg/tomcat5/common/lib/classes12.jar:/home/aceorg/tomcat5/common/lib/commons-dbcp-1.2.1.jar:/home/aceorg/tomcat5/common/lib/commons-pool-1.2.jar:/home/aceorg/aceorg/DEV-1.7/epoch-plugin/lib/mbt_1.1.2_bin.jar:/home/aceorg/aceorg/DEV-1.7/epoch-plugin/lib/LewisSketch.jar:/home/aceorg/aceorg/DEV-1.7/epoch-plugin/lib/gnu-regexp-1.1.4.jar:/home/aceorg/tomcat5/common/lib/servlet.jar MolTable.java


MolTable.java:147: exception chemaxon.jchem.db.UpdateHandlerException is never thrown in body of corresponding try statement


                        } catch (UpdateHandlerException e1) {


                          ^


1 error


make: *** [/home/aceorg/aceorg/DEV-1.7/epoch-plugin/build/com/prenhall/epoch/db/chem/MolTable.class] Error 1






I can catch the UpdateHandlerException with a general catch Exception, but Rafi suggested you might like to hear about this behavior.

ChemAxon aa7c50abf8

26-07-2007 20:01:37

Your Java compiler is actually right. The UpdateHandlerException is caught in UpdateHandler.execute(boolean) and an SQLException is thrown instead. The stack trace for UpdateHandlerException you quoted is written to stderr in UpdateHandler.execute(boolean). If you want to catch a Throwable more specific than Exception, look for SQLExceptions.





Admittedly, it is somewhat misleading to throw a SQLException for an empty molecule. The reason is that sometime in the early days (just a couple of seconds after the Big Bang :-) ), it had to be decided which exceptions UpdateHandler.execute should declare to throw and obviously SQLException alone made it into the throws clause. Time went by, the functionality got richer, but we have been "aggressive" in keeping our API backward compatible all along. That is why all exceptions thrown by UpdateHandler.execute have to be converted to SQLExceptions. (Maybe in our upcoming major release, we will revise the API in this respect.)





You have most probably noticed, so just in case: UpdateHandler has a setEmptyStructuresAllowed method to allow empty structures in the database.