public static void Do(System.Threading.ThreadStart testProc) { try { testProc(); } catch (Exception ex) { string stackTrace; ConsoleColor orgColor = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Red; WriteLineWithChar(Console.Error, '='); // print error message Console.Error.WriteLine(ex.Message); // trim last line of the stack trace because it always be this method. stackTrace = ex.StackTrace; try { int firstLineEnd = Utl.NextLineHead(stackTrace, 0); int lastLineHead = Utl.PrevLineHead(stackTrace, stackTrace.Length); stackTrace = stackTrace.Substring(firstLineEnd, lastLineHead - firstLineEnd - 1); } catch {} // print stack trace WriteLineWithChar(Console.Error, '-'); Console.Error.WriteLine(stackTrace); WriteLineWithChar(Console.Error, '='); Console.Error.WriteLine(); Console.ForegroundColor = orgColor; ErrorCount++; } }