C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Also: The #line default command is used. This changes the line numbers to how they would be if no #line directives were present.
Tip: The #line hidden command is used—this removes all line number information.
C# program that uses line directives
using System;
class Program
{
static void Main()
{
#line 999
throw new Exception();
#line default
throw new Exception();
#line hidden
throw new Exception();
}
}
Output
(Comment out first two exceptions to skip them.)
Unhandled Exception: ...Program.cs:line 999
Unhandled Exception: ...Program.cs:line 10
Unhandled Exception: ...Program.cs:line 0
Tip: You could inject #line directives to make exceptions report errors in the correct locations in the original (not generated) code.
And: If you need it, the line directive is useful. But in almost all programs, it is worthless.