Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Exception.cs « System « corlib « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cd951f302b9a426a4458eed8600ff2ecce1f0dbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
//
// System.Exception.cs
//
// Author:
//   Miguel de Icaza (miguel@ximian.com)
//
// (C) Ximian, Inc.  http://www.ximian.com
//

using System.Runtime.Serialization;
using System.Reflection;

namespace System {

	[Serializable]
//	[ClassInterface (ClassInterfaceType.AutoDual)] (no implementation yet)
	[MonoTODO]
	public class Exception : ISerializable {
		IntPtr [] trace_ips;
		Exception inner_exception;
		string message;
		string help_link;
		string class_name;
		string stack_trace = "TODO: implement stack traces";
		string remote_stack_trace = "TODO: Implement remote stack trace";
		int remote_stack_index;
		int hresult;
		string source;
		
		public Exception ()
		{
			inner_exception = null;
			message = "";
		}

		public Exception (string msg)
		{
			inner_exception = null;
			message = msg;
		}

		protected Exception (SerializationInfo info, StreamingContext sc)
		{
			if (info == null)
				throw new ArgumentNullException ("info");

			class_name      = info.GetString ("ClassName");
			message         = info.GetString ("Message");
			inner_exception = (Exception) info.GetValue  ("InnerException", typeof (Exception));
			help_link       = info.GetString ("HelpURL");
			stack_trace     = info.GetString ("StackTraceString");
			remote_stack_trace = info.GetString ("RemoteStackTrace");
			remote_stack_index = info.GetInt32  ("RemoteStackIndex");
			hresult            = info.GetInt32  ("HResult");
			source             = info.GetString ("Source");
		}

		public Exception (string msg, Exception e)
		{
			inner_exception = e;
			message = msg;
		}

		public Exception InnerException {
			get {
				return inner_exception;
			}
		}

		public virtual string HelpLink {
			get {
				return help_link;
			}

			set {
				help_link = value;
			}
		}

		protected int HResult {
			get {
				return hresult;
			}

			set {
				hresult = value;
			}
		}

		public virtual string Message {
			get {
				return message;
			}
		}

		[MonoTODO]
		public virtual string Source {
			get {
				// TODO: if source is null, we must return
				// the name of the assembly where the error
				// originated.
				return source;
			}

			set {
				source = value;
			}
		}

		public virtual string StackTrace {
			get {
				return stack_trace;
			}
		}

		[MonoTODO]
		public MethodBase TargetSite {
			get {
				// TODO: Implement this.
				return null;
			}
		}

		public virtual Exception GetBaseException ()
		{
			Exception inner = inner_exception;
				
			while (inner != null){
				if (inner.InnerException != null)
					inner = inner.InnerException;
				else
					return inner;
			}

			return this;
		}

		public virtual void GetObjectData (SerializationInfo info, StreamingContext context)
		{
			info.AddValue ("ClassName", class_name);
			info.AddValue ("Message",   message);
			info.AddValue ("InnerException", inner_exception);
			info.AddValue ("HelpURL",   help_link);
			info.AddValue ("StackTraceString", stack_trace);
			info.AddValue ("RemoteStackTrace", remote_stack_trace);
			info.AddValue ("RemoteStackIndex", remote_stack_index);
			info.AddValue ("HResult", hresult);
			info.AddValue ("Source", source);
		}

		public override string ToString ()
		{
			return this.GetType ().FullName + "\n" +
				message +
				GetBaseException ().GetType ().FullName +
				stack_trace;
		}
	}
}