// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) // This code is distributed under the GNU LGPL (for details please see \doc\license.txt) using System.Text; namespace Debugger { /// This convenience class provides access to an exception within the debugee. /// public class Exception: DebuggerObject { Value exception; public Value Value { get { return exception; } } public Exception(Value exception) { this.exception = exception; } /// The GetType().FullName of the exception. /// public string Type { get { return exception.Type.FullName; } } /// The Message property of the exception. /// public string Message { get { Value message = exception.GetMemberValue("_message"); return message.IsNull ? string.Empty : message.AsString(); } } /// The InnerException property of the exception. /// public Exception InnerException { get { Value innerException = exception.GetMemberValue("_innerException"); return innerException.IsNull ? null : new Exception(innerException); } } public void MakeValuePermanent() { exception = exception.GetPermanentReference(); } public override string ToString() { StringBuilder sb = new StringBuilder(); sb.Append(this.Type); if (!string.IsNullOrEmpty(this.Message)) { sb.Append(": "); sb.Append(this.Message); } if (this.InnerException != null) { sb.Append(" ---> "); sb.Append(this.InnerException.ToString()); } return sb.ToString(); } public string GetStackTrace() { return GetStackTrace("--- End of inner exception stack trace ---"); } /// Returs formated stacktrace for the exception /// Getting the stacktrace involves property /// evaluation so GetValueException can be thrown in some cicumstances. public string GetStackTrace(string endOfInnerExceptionFormat) { StringBuilder sb = new StringBuilder(); if (this.InnerException != null) { sb.Append(this.InnerException.GetStackTrace(endOfInnerExceptionFormat)); sb.Append(" "); sb.Append(endOfInnerExceptionFormat); sb.AppendLine(); } // Note that evaluation is not possible after a stackoverflow exception Value stackTrace = exception.GetMemberValue("StackTrace"); if (!stackTrace.IsNull) { sb.Append(stackTrace.AsString()); sb.AppendLine(); } return sb.ToString(); } } public class ExceptionEventArgs: ProcessEventArgs { readonly Exception exception; readonly ExceptionType exceptionType; readonly bool isUnhandled; public Exception Exception { get { return exception; } } public ExceptionType ExceptionType { get { return exceptionType; } } public bool IsUnhandled { get { return isUnhandled; } } public ExceptionEventArgs(Process process, Exception exception, ExceptionType exceptionType, bool isUnhandled):base(process) { this.exception = exception; this.exceptionType = exceptionType; this.isUnhandled = isUnhandled; } } }