program Project1;
{$mode ObjFPC}{$H+}
Uses Sysutils, Classes;
begin
Writeln('Filename='+{$I %FILE%});
Writeln('Line='+{$I %LINE%});
Readln;
end.
Returns
Filename=project1.lpr
Line=6Note: %LINE% returns the Line, on which this Include-Directive is called, not the Line which caused the Exception.
You have to do math there.
See also %LINENUM% which is the "same" as %LINE% but as an integer