Log query on exception