Added stacktrace printing to query error handler