My problem is as follows. I need to catch the exception on query in controller. Query depends on user input, so It is possible(and probable) that many times user will generate error. I want to handle it in my own way.
Without seeing the full stack trace I would gess that you have a problem connection to the database, that is why you get this error message as connection faliure happens before your query, so your query is not reached at all, so it can not catch the exception.
Connection seems to be good - it works fine everywhere else. If data from the the $str is correct, there is no error too. This happens only when query is invalid. Maybe attached will provide some more info.
Good point. Seems like the problem is that $q is lazy loaded and exception happens in Template, not Controller. How can I force the query to happen in Controller? (I guess Template is no good place for try/catch).