New test.
[mono.git] / mcs / class / Mono.Data.SybaseClient / Mono.Data.SybaseClient / SybaseException.cs
1 //
2 // Mono.Data.SybaseClient.SybaseException.cs
3 //
4 // Author:
5 //   Tim Coleman (tim@timcoleman.com)
6 //
7 // Copyright (C) Tim Coleman, 2002
8 //
9
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 using Mono.Data.Tds.Protocol;
32 using System;
33 using System.Data;
34 using System.Runtime.Serialization;
35 using System.Text;
36
37 namespace Mono.Data.SybaseClient {
38         [Serializable]
39         public sealed class SybaseException : SystemException
40         {
41                 #region Fields
42
43                 SybaseErrorCollection errors; 
44
45                 #endregion Fields
46
47                 #region Constructors
48
49                 internal SybaseException () 
50                         : base ("a SQL Exception has occurred.") 
51                 {
52                         errors = new SybaseErrorCollection();
53                 }
54
55                 internal SybaseException (byte theClass, int lineNumber, string message, int number, string procedure, string server, string source, byte state) 
56                         : base (message) 
57                 {
58                         errors = new SybaseErrorCollection (theClass, lineNumber, message, number, procedure, server, source, state);
59                 }
60
61                 #endregion // Constructors
62
63                 #region Properties
64
65                 public byte Class {
66                         get { return errors [0].Class; }
67                 }
68
69                 public SybaseErrorCollection Errors {
70                         get { return errors; }
71                 }
72
73                 public int LineNumber {
74                         get { return errors [0].LineNumber; }
75                 }
76                 
77                 public override string Message  {
78                         get {
79                                 StringBuilder result = new StringBuilder ();
80                                 foreach (SybaseError error in Errors) {
81                                         if (result.Length > 0)
82                                                 result.Append ('\n');
83                                         result.Append (error.Message);
84                                 }
85                                 return result.ToString ();
86                         }                                                                
87                 }
88                 
89                 public int Number {
90                         get { return errors [0].Number; }
91                 }
92                 
93                 public string Procedure {
94                         get { return errors [0].Procedure; }
95                 }
96
97                 public string Server {
98                         get { return errors [0].Server; }
99                 }
100                 
101                 public override string Source {
102                         get { return errors [0].Source; }
103                 }
104
105                 public byte State {
106                         get { return errors [0].State; }
107                 }
108
109                 #endregion // Properties
110
111                 #region Methods
112
113                 [MonoTODO]
114                 public override void GetObjectData (SerializationInfo si, StreamingContext context) 
115                 {
116                         throw new NotImplementedException ();
117                 }
118
119                 internal static SybaseException FromTdsInternalException (TdsInternalException e)
120                 {
121                         return new SybaseException (e.Class, e.LineNumber, e.Message, e.Number, e.Procedure, e.Server, "Mono SybaseClient Data Provider", e.State);
122                 }
123
124                 #endregion // Methods
125         }
126 }