* attribute.cs (GetMarshal): Work even if "DefineCustom" is
[mono.git] / mcs / class / FirebirdSql.Data.Firebird / FirebirdSql.Data.Firebird / FbException.cs
1 /*\r
2  *      Firebird ADO.NET Data provider for .NET and     Mono \r
3  * \r
4  *         The contents of this file are subject to the Initial \r
5  *         Developer's Public License Version 1.0 (the "License"); \r
6  *         you may not use this file except in compliance with the \r
7  *         License. You may obtain a copy of the License at \r
8  *         http://www.firebirdsql.org/index.php?op=doc&id=idpl\r
9  *\r
10  *         Software distributed under the License is distributed on \r
11  *         an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either \r
12  *         express or implied. See the License for the specific \r
13  *         language governing rights and limitations under the License.\r
14  * \r
15  *      Copyright (c) 2002, 2005 Carlos Guzman Alvarez\r
16  *      All Rights Reserved.\r
17  */\r
18 \r
19 using System;\r
20 using System.ComponentModel;\r
21 using System.Security.Permissions;\r
22 using FirebirdSql.Data.Common;\r
23 \r
24 namespace FirebirdSql.Data.Firebird\r
25 {\r
26         /// <include file='Doc/en_EN/FbException.xml' path='doc/class[@name="FbException"]/overview/*'/>\r
27 #if     (!NETCF)\r
28         [Serializable]\r
29 #endif\r
30         public sealed class FbException : SystemException\r
31         {\r
32                 #region Fields\r
33 \r
34                 private FbErrorCollection errors = new FbErrorCollection();\r
35                 private int errorCode;\r
36 \r
37                 #endregion\r
38 \r
39                 #region Properties\r
40 \r
41                 /// <include file='Doc/en_EN/FbException.xml' path='doc/class[@name="FbException"]/property[@name="Errors"]/*'/>\r
42 #if     (!NETCF)\r
43                 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]\r
44 #endif\r
45                 public FbErrorCollection Errors\r
46                 {\r
47                         get { return this.errors; }\r
48                 }\r
49 \r
50                 /// <include file='Doc/en_EN/FbException.xml' path='doc/class[@name="FbException"]/property[@name="ErrorCode"]/*'/>\r
51                 public int ErrorCode\r
52                 {\r
53                         get { return this.errorCode; }\r
54                 }\r
55 \r
56                 #endregion\r
57 \r
58                 #region Constructors\r
59 \r
60                 internal FbException() : base()\r
61                 {\r
62                 }\r
63 \r
64                 internal FbException(string message) : base(message)\r
65                 {\r
66                 }\r
67 \r
68                 internal FbException(string message, IscException ex) : base(message)\r
69                 {\r
70                         this.errorCode = ex.ErrorCode;\r
71 #if     (!NETCF)\r
72                         this.Source = ex.Source;\r
73 #endif\r
74 \r
75                         this.GetIscExceptionErrors(ex);\r
76                 }\r
77 \r
78 #if     (!NETCF)\r
79 \r
80                 internal FbException(\r
81             System.Runtime.Serialization.SerializationInfo info, \r
82             System.Runtime.Serialization.StreamingContext context) : base(info, context)\r
83                 {\r
84                         this.errors = (FbErrorCollection)info.GetValue("errors", typeof(FbErrorCollection));\r
85                         this.errorCode = info.GetInt32("errorCode");\r
86                 }\r
87 \r
88 #endif\r
89 \r
90                 #endregion\r
91 \r
92                 #region Methods\r
93 \r
94 #if     (!NETCF)\r
95 \r
96                 /// <include file='Doc/en_EN/FbException.xml' path='doc/class[@name="FbException"]/method[@name="GetObjectData(SerializationInfo, StreamingContext)"]/*'/>\r
97                 [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)]\r
98                 public override void GetObjectData(\r
99             System.Runtime.Serialization.SerializationInfo info, \r
100             System.Runtime.Serialization.StreamingContext context)\r
101                 {\r
102                         info.AddValue("errors", this.errors);\r
103                         info.AddValue("errorCode", this.errorCode);\r
104 \r
105                         base.GetObjectData(info, context);\r
106                 }\r
107 \r
108 #endif\r
109 \r
110                 #endregion\r
111 \r
112                 #region Internal Methods\r
113 \r
114                 internal void GetIscExceptionErrors(IscException ex)\r
115                 {\r
116                         foreach (IscError error in ex.Errors)\r
117                         {\r
118                                 this.errors.Add(error.Message, error.ErrorCode);\r
119                         }\r
120                 }\r
121 \r
122                 #endregion\r
123         }\r
124 }\r