How to get line_number and file_name of an exception


My goal is to get the file_name where an exception happened and its
line_number. The way it's made in Rails is awkward as it gets computed
in class TemplateError < ActionViewError which is in the view.

So how to write my own exception handler and use line_number and
file_name which Rails can compute?