[runtime] Overwrite stacktrace for exception on re-throw. Fixes #1856.
[mono.git] / mcs / class / System.Data / System.Data.OleDb / OleDbException.cs
1 //
2 // System.Data.OleDb.OleDbException
3 //
4 // Author:
5 //   Rodrigo Moya (rodrigo@ximian.com)
6 //   Tim Coleman (tim@timcoleman.com)
7 //
8 // Copyright (C) Rodrigo Moya, 2002
9 // Copyright (C) Tim Coleman, 2002
10 //
11
12 //
13 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
14 //
15 // Permission is hereby granted, free of charge, to any person obtaining
16 // a copy of this software and associated documentation files (the
17 // "Software"), to deal in the Software without restriction, including
18 // without limitation the rights to use, copy, modify, merge, publish,
19 // distribute, sublicense, and/or sell copies of the Software, and to
20 // permit persons to whom the Software is furnished to do so, subject to
21 // the following conditions:
22 // 
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
25 // 
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 //
34
35 using System.ComponentModel;
36 using System.Data;
37 using System.Data.Common;
38 using System.Globalization;
39 using System.Runtime.InteropServices;
40 using System.Runtime.Serialization;
41
42 namespace System.Data.OleDb
43 {
44         [Serializable]
45         public sealed class OleDbException : DbException
46         {
47                 private OleDbConnection connection;
48
49                 #region Constructors
50
51                 internal OleDbException (OleDbConnection cnc)
52                 {
53                         connection = cnc;
54                 }
55                 
56                 #endregion // Constructors
57                 
58                 #region Properties
59
60                 [TypeConverterAttribute (typeof (OleDbException.ErrorCodeConverter))]
61                 public override int ErrorCode {
62                         get {
63                                 GdaList glist;
64                                 IntPtr errors;
65
66                                 errors = libgda.gda_connection_get_errors (connection.GdaConnection);
67                                 if (errors != IntPtr.Zero) {
68                                         glist = (GdaList) Marshal.PtrToStructure (errors, typeof (GdaList));
69                                         return (int) libgda.gda_error_get_number (glist.data);
70                                 }
71
72                                 return -1;
73                         }
74                 }
75                 
76                 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
77                 public OleDbErrorCollection Errors {
78                         get {
79                                 GdaList glist;
80                                 IntPtr errors;
81                                 OleDbErrorCollection col = new OleDbErrorCollection ();
82                                 
83                                 errors = libgda.gda_connection_get_errors (connection.GdaConnection);
84                                 if (errors != IntPtr.Zero) {
85                                         glist = (GdaList) Marshal.PtrToStructure (errors, typeof (GdaList));
86                                         while (glist != null) {
87                                                 col.Add (new OleDbError (
88                                                                  libgda.gda_error_get_description (glist.data),
89                                                                  (int) libgda.gda_error_get_number (glist.data),
90                                                                  libgda.gda_error_get_source (glist.data),
91                                                                  libgda.gda_error_get_sqlstate (glist.data)));
92                                                 glist = (GdaList) Marshal.PtrToStructure (glist.next,
93                                                                                           typeof (GdaList));
94                                         }
95                                 }
96
97                                 return col;
98                         }
99                 }
100
101                 new public string Message {
102                         get {
103                                 GdaList glist;
104                                 IntPtr errors;
105                                 string msg = "";
106
107                                 errors = libgda.gda_connection_get_errors (connection.GdaConnection);
108                                 if (errors != IntPtr.Zero) {
109                                         glist = (GdaList) Marshal.PtrToStructure (errors, typeof (GdaList));
110                                         while (glist != null) {
111                                                 msg = msg + ";" +  libgda.gda_error_get_description (glist.data);
112                                                 glist = (GdaList) Marshal.PtrToStructure (glist.next,
113                                                                                           typeof (GdaList));
114                                         }
115
116                                         return msg;
117                                 }
118
119                                 return null;
120                         }
121                 }
122
123                 new public string Source {
124                         get {
125                                 GdaList glist;
126                                 IntPtr errors;
127
128                                 errors = libgda.gda_connection_get_errors (connection.GdaConnection);
129                                 if (errors != IntPtr.Zero) {
130                                         glist = (GdaList) Marshal.PtrToStructure (errors, typeof (GdaList));
131                                         return libgda.gda_error_get_source (glist.data);
132                                 }
133
134                                 return null;
135                         }
136                 }
137
138                 #endregion // Properties
139
140                 #region Methods
141
142                 public override void GetObjectData (SerializationInfo si, StreamingContext context)
143                 {
144                         if (si == null)
145                                 throw new ArgumentNullException ("si");
146
147                         si.AddValue ("connection", connection);
148                         base.GetObjectData (si, context);
149                         throw new NotImplementedException ();
150                 }
151
152                 #endregion // Methods
153
154                 internal sealed class ErrorCodeConverter : Int32Converter
155                 {
156                         [MonoTODO]
157                         public override object ConvertTo (ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) {
158                                 return base.ConvertTo (context, culture, value, destinationType);
159                         }
160                 }
161         }
162 }