tweak try-except to handle SQL errors better

This should hopefully fix any issues with mogrifying SQL queries to see what went wrong with an SQL call.