6 using System.Windows.Forms;
14 return Environment.GetCommandLineArgs().Skip(1).ToArray();
19 var body =
new StringBuilder();
25 body.AppendFormat(
"User: {0}\n", Environment.UserName);
26 body.AppendFormat(
"Current Directory: {0}\n", Environment.CurrentDirectory);
27 body.AppendFormat(
"OS Version: {0}\n", Environment.OSVersion);
28 body.AppendFormat(
"Command Line Args: {0}\n", string.Join(
" ", GetCommandLineArgs()));
29 PrintExceptionRecursively(body, e);
30 var errorMessage = body.ToString();
33 Clipboard.SetText(errorMessage);
42 private static void PrintExceptionRecursively(StringBuilder builder,
Exception exception,
int indent = 0)
44 PrintException(builder, exception, indent);
45 if (exception == null)
48 var aggregate = exception as AggregateException;
49 if (aggregate != null)
51 builder.AppendLine(
"The above exception is an aggregate exception. Printing inner exceptions:");
57 foreach (var innerException
in aggregate.InnerExceptions)
59 PrintExceptionRecursively(builder, innerException, indent + 2);
62 else if (exception.InnerException != null)
64 builder.AppendLine(
"The above exception has an inner exception:");
65 PrintExceptionRecursively(builder, exception.InnerException, indent + 2);
69 private static void PrintException(StringBuilder builder,
Exception exception,
int indent)
71 if (exception == null)
73 builder.AppendFormat(
"{0}Exception type: (null)\n", Indent(indent));
77 builder.AppendFormat(
"{0}Exception type: {1}\n", Indent(indent), exception.GetType().Name);
78 builder.AppendFormat(
"{0}Exception message: {1}\n", Indent(indent), exception.Message);
79 builder.AppendFormat(
"{0}StackTrace: {1}\n", Indent(indent), exception.StackTrace);
83 private static string Indent(
int offset)
85 return "".PadLeft(offset);
static string[] GetCommandLineArgs()
static string BuildErrorToClipboard(Exception e, string header=null)