Show line number in exception handling
Use ex.ToString() to get the full stack trace. You must compile with debugging symbols (.pdb files), even in release mode, to get the line numbers (this is an option in the project build properties).
Use ex.ToString() to get the full stack trace. You must compile with debugging symbols (.pdb files), even in release mode, to get the line numbers (this is an option in the project build properties).
With :%s/^/\=line(‘.’)/ EDIT: to sum up the comments. This command can be tweaked as much as you want. Let’s say you want to add numbers in front of lines from a visual selection (V + move), and you want the numbering to start at 42. :'<,’>s/^/\=(line(‘.’)-line(“‘<“)+42)/ If you want to add a string between the … Read more
You can’t get human-readable line numbers with git diff There aren’t currently any options to get line-numbers displayed vertically on the side with git diff. Unified-diff format That information is available in the (c)hunk headers for each change in the diff though, it’s just in unified-diff format: @@ -start,count +start,count @@ The original state of … Read more
This is a slight modification from: http://msdn.microsoft.com/en-us/library/aa287535%28VS.71%29.aspx int counter = 0; string line; // Read the file and display it line by line. System.IO.StreamReader file = new System.IO.StreamReader(“c:\\test.txt”); while((line = file.ReadLine()) != null) { if ( line.Contains(“word”) ) { Console.WriteLine (counter.ToString() + “: ” + line); } counter++; } file.Close();
var thisline = new Error().lineNumber If that doesn’t work in whatever environment you’re using, you can try: var stack = new Error().stack Then hunt through the stack for the line number.
You should use the preprocessor macro __LINE__ and __FILE__. They are predefined macros and part of the C/C++ standard. During preprocessing, they are replaced respectively by a constant string holding an integer representing the current line number and by the current file name. Others preprocessor variables : __func__ : function name (this is part of … Read more
If you want to delete lines from 5 through 10 and line 12th: sed -e ‘5,10d;12d’ file This will print the results to the screen. If you want to save the results to the same file: sed -i.bak -e ‘5,10d;12d’ file This will store the unmodified file as file.bak, and delete the given lines. Note: … Read more
In .NET 4.5 / C# 5, you can get the compiler to do this work for you, by writing a utility method that uses the new caller attributes: using System.Runtime.CompilerServices; static void SomeMethodSomewhere() { ShowMessage(“Boo”); } … static void ShowMessage(string message, [CallerLineNumber] int lineNumber = 0, [CallerMemberName] string caller = null) { MessageBox.Show(message + ” … Read more
This is the fastest version I have found so far, about 6 times faster than readLines. On a 150MB log file this takes 0.35 seconds, versus 2.40 seconds when using readLines(). Just for fun, linux’ wc -l command takes 0.15 seconds. public static int countLinesOld(String filename) throws IOException { InputStream is = new BufferedInputStream(new FileInputStream(filename)); … Read more
Go into the Properties window for the project where you want to see stack trace line numbers. Click on the Build “vertical tab”. Select “Release” configuration. Check the DEBUG constant parameter. Uncheck the “Optimize code” parameter to avoid the occasional trace issue with inlined code (this step is not essential). Press the Advanced… button and … Read more