Better query exception reporting (fixes #14)