Thanks for your response.
The problem is, mysqli does not throw an exception nor produce an error on invalid SQL, or on another error from database. So we need to check manually. That's why I've extended the mysqli class to check for error after each query() and prepare().
In case of error, I throw a custom exception, but this exception is thrown from db.php where mysqli is extended and where custom query() method is checking for errors and throwing exceptions on errors, not from somescript.php that did the query, and this is my main problem. I need to know the line in somescript.php (and the filename "somescript.php") where the method was called.
I also have custom error handler that translates PHP errors (or custom errors via trigger_error) into exceptions.
In fact, my problem has nothing to do with exceptions or errors (since I throw my own), I just mentioned it to present the environment of my problem. All I need is to know line number and file from which some function (or method) was called, and I need to know it within that function (or method). Is there a way for a function to "know" from where it was called?