~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/Debugger/Debugger.Core/Exception.cs

  • Committer: sk
  • Date: 2011-09-10 05:17:57 UTC
  • Revision ID: halega@halega.com-20110910051757-qfouz1llya9m6boy
4.1.0.7915 Release Candidate 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
 
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
 
3
 
 
4
using System.Text;
 
5
 
 
6
namespace Debugger
 
7
{       
 
8
        /// <summary> This convenience class provides access to an exception within the debugee. </summary>
 
9
        /// <seealso cref="System.Exception" />
 
10
        public class Exception: DebuggerObject
 
11
        {
 
12
                Value exception;
 
13
                
 
14
                public Value Value {
 
15
                        get { return exception; }
 
16
                }
 
17
                
 
18
                public Exception(Value exception)
 
19
                {
 
20
                        this.exception = exception;
 
21
                }
 
22
                
 
23
                /// <summary> The <c>GetType().FullName</c> of the exception. </summary>
 
24
                /// <seealso cref="System.Exception" />
 
25
                public string Type {
 
26
                        get {
 
27
                                return exception.Type.FullName;
 
28
                        }
 
29
                }
 
30
                
 
31
                /// <summary> The <c>Message</c> property of the exception. </summary>
 
32
                /// <seealso cref="System.Exception" />
 
33
                public string Message {
 
34
                        get {
 
35
                                Value message = exception.GetMemberValue("_message");
 
36
                                return message.IsNull ? string.Empty : message.AsString();
 
37
                        }
 
38
                }
 
39
                
 
40
                /// <summary> The <c>InnerException</c> property of the exception. </summary>
 
41
                /// <seealso cref="System.Exception" />
 
42
                public Exception InnerException {
 
43
                        get {
 
44
                                Value innerException = exception.GetMemberValue("_innerException");
 
45
                                return innerException.IsNull ? null : new Exception(innerException);
 
46
                        }
 
47
                }
 
48
                
 
49
                public void MakeValuePermanent()
 
50
                {
 
51
                        exception = exception.GetPermanentReference();
 
52
                }
 
53
                
 
54
                public override string ToString()
 
55
                {
 
56
                        StringBuilder sb = new StringBuilder();
 
57
                        sb.Append(this.Type);
 
58
                        if (!string.IsNullOrEmpty(this.Message)) {
 
59
                                sb.Append(": ");
 
60
                                sb.Append(this.Message);
 
61
                        }
 
62
                        if (this.InnerException != null) {
 
63
                                sb.Append(" ---> ");
 
64
                                sb.Append(this.InnerException.ToString());
 
65
                        }
 
66
                        return sb.ToString();
 
67
                }
 
68
                
 
69
                public string GetStackTrace()
 
70
                {
 
71
                        return GetStackTrace("--- End of inner exception stack trace ---");
 
72
                }
 
73
                
 
74
                /// <summary> Returs formated stacktrace for the exception </summary>
 
75
                /// <exception cref="GetValueException"> Getting the stacktrace involves property
 
76
                /// evaluation so GetValueException can be thrown in some cicumstances. </exception>
 
77
                public string GetStackTrace(string endOfInnerExceptionFormat)
 
78
                {
 
79
                        StringBuilder sb = new StringBuilder();
 
80
                        if (this.InnerException != null) {
 
81
                                sb.Append(this.InnerException.GetStackTrace(endOfInnerExceptionFormat));
 
82
                                sb.Append("   ");
 
83
                                sb.Append(endOfInnerExceptionFormat);
 
84
                                sb.AppendLine();
 
85
                        }
 
86
                        // Note that evaluation is not possible after a stackoverflow exception
 
87
                        Value stackTrace = exception.GetMemberValue("StackTrace");
 
88
                        if (!stackTrace.IsNull) {
 
89
                                sb.Append(stackTrace.AsString());
 
90
                                sb.AppendLine();
 
91
                        }
 
92
                        return sb.ToString();
 
93
                }
 
94
        }
 
95
        
 
96
        public class ExceptionEventArgs: ProcessEventArgs
 
97
        {
 
98
            readonly Exception exception;
 
99
            readonly ExceptionType exceptionType;
 
100
            readonly bool isUnhandled;
 
101
                
 
102
                public Exception Exception {
 
103
                        get { return exception; }
 
104
                }
 
105
                
 
106
                public ExceptionType ExceptionType {
 
107
                        get { return exceptionType; }
 
108
                }
 
109
                
 
110
                public bool IsUnhandled {
 
111
                        get { return isUnhandled; }
 
112
                }
 
113
                
 
114
                public ExceptionEventArgs(Process process, Exception exception, ExceptionType exceptionType, bool isUnhandled):base(process)
 
115
                {
 
116
                        this.exception = exception;
 
117
                        this.exceptionType = exceptionType;
 
118
                        this.isUnhandled = isUnhandled;
 
119
                }
 
120
        }
 
121
}