-
Notifications
You must be signed in to change notification settings - Fork 263
/
DataException.cs
58 lines (52 loc) · 2.47 KB
/
DataException.cs
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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Diagnostics;
using Microsoft.Data.SqlClient;
namespace Microsoft.Data
{
// These functions are major point of localization.
// We need to have a rules to enforce consistency there.
// The dangerous point there are the string arguments of the exported (internal) methods.
// This string can be argument, table or constraint name but never text of exception itself.
// Make an invariant that all texts of exceptions coming from resources only.
internal static class ExceptionBuilder
{
// The class defines the exceptions that are specific to the DataSet.
// The class contains functions that take the proper informational variables and then construct
// the appropriate exception with an error string obtained from the resource Data.txt.
// The exception is then returned to the caller, so that the caller may then throw from its
// location so that the catcher of the exception will have the appropriate call stack.
// This class is used so that there will be compile time checking of error messages.
// The resource Data.txt will ensure proper string text based on the appropriate
// locale.
static private void TraceException(
string trace, Exception e)
{
Debug.Assert(null != e, "TraceException: null Exception");
if (null != e)
{
SqlClientEventSource.Log.TryAdvancedTraceEvent(trace, e.Message);
SqlClientEventSource.Log.TryAdvancedTraceEvent("<comm.ADP.TraceException|ERR|ADV> Environment StackTrace = '{0}'", Environment.StackTrace);
}
}
internal static void TraceExceptionAsReturnValue(Exception e)
{
TraceException("<comm.ADP.TraceException|ERR|THROW> Message='{0}'", e);
}
//
// COM+ exceptions
//
internal static ArgumentException _Argument(string error)
{
ArgumentException e = new ArgumentException(error);
ExceptionBuilder.TraceExceptionAsReturnValue(e);
return e;
}
public static Exception InvalidOffsetLength()
{
return _Argument(StringsHelper.GetString(Strings.Data_InvalidOffsetLength));
}
}// ExceptionBuilder
}