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 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
|
//
// System.Data.Common.ExceptionHelper
//
// Author:
// Boris Kirzner (borisk@mainsoft.com)
//
using System;
namespace System.Data.Common
{
internal sealed class ExceptionHelper
{
internal static ArgumentException InvalidSizeValue (int value)
{
string [] args = new string [] {value.ToString ()};
return new ArgumentException (GetExceptionMessage ("Invalid parameter Size value '{0}'. The value must be greater than or equal to 0.",args));
}
internal static ArgumentException InvalidEnumValueException (String enumeration, object value)
{
return new ArgumentException (String.Format ("The {0} enumeration value, {1}, is invalid", enumeration, value));
}
internal static ArgumentOutOfRangeException InvalidDataRowVersion (DataRowVersion value)
{
object [] args = new object [] { "DataRowVersion", value.ToString () } ;
return new ArgumentOutOfRangeException (GetExceptionMessage ("{0}: Invalid DataRow Version enumeration value: {1}",args));
}
internal static ArgumentOutOfRangeException InvalidParameterDirection (ParameterDirection value)
{
object [] args = new object [] { "ParameterDirection", value.ToString () } ;
return new ArgumentOutOfRangeException (GetExceptionMessage ("Invalid direction '{0}' for '{1}' parameter.",args));
}
internal static InvalidOperationException NoStoredProcedureExists (string procedureName) {
object [] args = new object [1] { procedureName } ;
return new InvalidOperationException (GetExceptionMessage ("The stored procedure '{0}' doesn't exist.", args));
}
internal static ArgumentNullException ArgumentNull (string parameter)
{
return new ArgumentNullException (parameter);
}
internal static InvalidOperationException TransactionRequired ()
{
return new InvalidOperationException (GetExceptionMessage ("Execute requires the command to have a transaction object when the connection assigned to the command is in a pending local transaction. The Transaction property of the command has not been initialized."));
}
internal static ArgumentOutOfRangeException InvalidOleDbType (int value)
{
string [] args = new string [] { value.ToString() };
return new ArgumentOutOfRangeException (GetExceptionMessage ("Invalid OleDbType enumeration value: {0}",args));
}
internal static ArgumentException InvalidDbType(int value)
{
string [] args = new string [] { value.ToString () };
return new ArgumentException (GetExceptionMessage ("No mapping exists from DbType {0} to a known {1}.",args));
}
internal static InvalidOperationException DeriveParametersNotSupported(Type type,CommandType commandType)
{
string [] args = new string [] { type.ToString(),commandType.ToString() };
return new InvalidOperationException (GetExceptionMessage ("{0} DeriveParameters only supports CommandType.StoredProcedure, not CommandType.{1}.",args));
}
internal static InvalidOperationException ReaderClosed (string mehodName)
{
string [] args = new string [] { mehodName };
return new InvalidOperationException (GetExceptionMessage ("Invalid attempt to {0} when reader is closed.",args));
}
internal static ArgumentOutOfRangeException InvalidSqlDbType (int value)
{
string [] args = new string [] { value.ToString () };
return new ArgumentOutOfRangeException (GetExceptionMessage ("{0}: Invalid SqlDbType enumeration value: {1}.",args));
}
internal static ArgumentException UnknownDataType (string type1, string type2)
{
string [] args = new string [] { type1, type2 };
return new ArgumentException (GetExceptionMessage ("No mapping exists from DbType {0} to a known {1}.",args));
}
internal static InvalidOperationException TransactionNotInitialized ()
{
return new InvalidOperationException (GetExceptionMessage ("Execute requires the command to have a transaction object when the connection assigned to the command is in a pending local transaction. The Transaction property of the command has not been initialized."));
}
internal static InvalidOperationException ParametersNotInitialized (int parameterPosition,string parameterName,string parameterType)
{
object [] args = new object [] { parameterPosition, parameterName, parameterType };
return new InvalidOperationException (GetExceptionMessage ("Parameter {0}: '{1}', the property DbType is uninitialized: OleDbType.{2}.",args));
}
internal static InvalidOperationException WrongParameterSize(string provider)
{
string [] args = new string [] { provider };
return new InvalidOperationException (GetExceptionMessage ("{0}.Prepare method requires all variable length parameters to have an explicitly set non-zero Size.",args));
}
internal static InvalidOperationException ConnectionNotOpened (string operationName, string connectionState)
{
object [] args = new object [] { operationName, connectionState };
return new InvalidOperationException (GetExceptionMessage ("{0} requires an open and available Connection. The connection's current state is {1}.",args));
}
internal static InvalidOperationException ConnectionNotInitialized (string methodName)
{
object [] args = new object [] { methodName };
return new InvalidOperationException (GetExceptionMessage ("{0}: Connection property has not been initialized.",args));
}
internal static InvalidOperationException OpenConnectionRequired (string methodName, object connectionState)
{
object [] args = new object [] { methodName, connectionState };
return new InvalidOperationException (GetExceptionMessage ("{0} requires an open and available Connection. The connection's current state is {1}.",args));
}
internal static InvalidOperationException OpenedReaderExists ()
{
return new InvalidOperationException (GetExceptionMessage ("There is already an open DataReader associated with this Connection which must be closed first."));
}
internal static InvalidOperationException ConnectionAlreadyOpen (object connectionState)
{
object [] args = new object [] { connectionState };
return new InvalidOperationException (GetExceptionMessage ("The connection is already Open (state={0}).",args));
}
internal static InvalidOperationException ConnectionStringNotInitialized ()
{
return new InvalidOperationException (GetExceptionMessage ("The ConnectionString property has not been initialized."));
}
internal static InvalidOperationException ConnectionIsBusy (object commandType,object connectionState)
{
object [] args = new object [] { commandType.ToString (), connectionState.ToString () };
return new InvalidOperationException (GetExceptionMessage ("The {0} is currently busy {1}.",args));
}
internal static InvalidOperationException NotAllowedWhileConnectionOpen (string propertyName, object connectionState)
{
object [] args = new object [] { propertyName, connectionState };
return new InvalidOperationException (GetExceptionMessage ("Not allowed to change the '{0}' property while the connection (state={1}).",args));
}
internal static ArgumentException OleDbNoProviderSpecified ()
{
return new ArgumentException (GetExceptionMessage ("An OLE DB Provider was not specified in the ConnectionString. An example would be, 'Provider=SQLOLEDB;'."));
}
internal static ArgumentException InvalidValueForKey (string key)
{
string [] args = new string [] { key };
return new ArgumentException (String.Format ("Invalid value for key {0}",args));
}
internal static InvalidOperationException ParameterSizeNotInitialized( int parameterIndex, string parameterName,string parameterType,int parameterSize)
{
object [] args = new object [] { parameterIndex.ToString (), parameterName, parameterType, parameterSize.ToString () };
return new InvalidOperationException (GetExceptionMessage ("Parameter {0}: '{1}' of type: {2}, the property Size has an invalid size: {3}",args));
}
internal static ArgumentException InvalidUpdateStatus (UpdateStatus status)
{
object [] args = new object [] { status };
return new ArgumentException (GetExceptionMessage ("Invalid UpdateStatus: {0}",args));
}
internal static InvalidOperationException UpdateRequiresCommand (string command)
{
object [] args = new object [] { command };
return new InvalidOperationException (GetExceptionMessage ("Auto SQL generation during {0} requires a valid SelectCommand.",args));
}
internal static DataException RowUpdatedError ()
{
return new DataException (GetExceptionMessage ("RowUpdatedEvent: Errors occurred; no additional is information available."));
}
internal static ArgumentNullException CollectionNoNullsAllowed (object collection, object objectsType)
{
object [] args = new object [] {collection.GetType ().ToString (), objectsType.ToString ()};
return new ArgumentNullException (GetExceptionMessage ("The {0} only accepts non-null {1} type objects."));
}
internal static ArgumentException CollectionAlreadyContains(object objectType,string propertyName, object propertyValue, object collection)
{
object [] args = new object [] {objectType.ToString (), propertyName, propertyValue, collection.GetType ().ToString ()};
return new ArgumentException (GetExceptionMessage ("The {0} with {1} '{2}' is already contained by this {3}.",args));
}
internal static string GetExceptionMessage (string exceptionMessage,object [] args)
{
if ((args == null) || (args.Length == 0)) {
return exceptionMessage;
}
else {
return String.Format (exceptionMessage,args);
}
}
internal static string GetExceptionMessage (string exceptionMessage)
{
return GetExceptionMessage (exceptionMessage,null);
}
}
}
|