Neil Hughes wrote:
I'm trying to drag myself into the 21st century when it comes to coding,
partly though calling all of my old C code through Python (going OK so
far) and also by using JDBC along with the ODBC stuff I already know. And
what better way to do that than through Jython to help leverage my
limited knowledge of Java.
It didn't take me long to hit a problem :-)
The JDBC driver is for the Pervasive.SQL database and my code performs a
simple table query without any problem. I wanted to handle the exceptions
that might be returned from the driver in a helpful fashion to the user
but my attempts at catching them seem to be failing. A slightly cut-down
version of the code so far:
------
import com.ziclix.python.sql as sql
import sys
from java import net
DSN = "jdbc:pervasive://%s" % (sys.argv[1],)
try:
Id = int(sys.argv[2]) # this can raise a ValueError exception
db = sql.zxJDBC.connect(DSN, None, None,
"com.pervasive.jdbc.v2.Driver") # this can raise a MalformedURLException
cursor = db.cursor()
queryString = "SELECT prnqueue_index_no, report_filename,
print_device, omega_user_name, error_code FROM sys_prnqueue_table ORDER
BY prnqueue_index_no"
cursor.execute(queryString)
# need to process the rows here
cursor.close()
db.close()
except net.MalformedURLException:
print "Error: Invalid or non-existent datasource name"
except ValueError:
print "Error: Incorrect parameter type used"
except Exception, e:
print "Pervasive.SQL error:"
print e
-------
By deliberately passing an illegal second parameter I can raise the
ValueError exception, but if I specify an incorrect datasource name (DSN)
the exception is not caught by net.MalformedURLException, but by the last
except (the one that prints "Pervasive.SQL error:").
What exactly is catched there? what does the scond print say?
So....a Java exception returned from Java code is handled differently
than one raised within Jython? I've been Googling and paging through my
Jython Essentials book, but I'm missing something.
Ususally _not_.
Regards,
Diez
-------------------------------------------------------
This SF.Net email is sponsored by Yahoo.
Introducing Yahoo! Search Developer Network - Create apps using Yahoo!
Search APIs Find out how you can build Yahoo! directly into your own
Applications - visit
http://developer.yahoo.net/?fr=offad-ysdn-ostg-q22005
|