You mean how to pull out details of the error that you’ve caught? You can catch the exception and learn about its cause like this:
import sys
from java.lang import Exception
try:
system.db.runQuery("SELECT something FROM nothing")
print 'Success!'
except Exception, errinfo:
print 'Error running query: ', errinfo.cause.message