Skip to content

Commit 699db48

Browse files
fredericDelaportehazzik
authored andcommitted
Cease throwing bare Exception (#1498)
1 parent ba8fb89 commit 699db48

File tree

17 files changed

+78
-71
lines changed

17 files changed

+78
-71
lines changed

src/NHibernate.DomainModel/Foo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ public FooComponent Component
322322
public FooComponent NullComponent
323323
{
324324
get { return null; }
325-
set { if (value != null) throw new Exception("Null component"); }
325+
set { if (value != null) throw new ArgumentException("Null component"); }
326326
}
327327

328328
#endregion
@@ -432,4 +432,4 @@ public bool EqualsFoo(Foo other)
432432

433433
private static int count = 0;
434434
}
435-
}
435+
}

src/NHibernate.DomainModel/FooComponent.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ private String NullString
110110
set
111111
{
112112
if (value != null)
113-
throw new Exception("null component property");
113+
throw new ArgumentException("null component property");
114114
}
115115
}
116116

@@ -179,4 +179,4 @@ public override string ToString()
179179

180180
#endregion
181181
}
182-
}
182+
}

src/NHibernate.Test/Async/NHSpecificTest/NH2583/Domain.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public partial class MyBO
7878
set(await (bo.GetOrCreateBO1Async(s, cancellationToken)), 1);
7979
break;
8080
default:
81-
throw new Exception("Value " + value + " not handled in code");
81+
throw new NotImplementedException("Value " + value + " not handled in code");
8282
}
8383
}
8484

@@ -114,7 +114,7 @@ public partial class MyBO
114114
set(await (bo.GetOrCreateBO2Async(s, cancellationToken)), 1);
115115
break;
116116
default:
117-
throw new Exception("Value " + value + " not handled in code");
117+
throw new NotImplementedException("Value " + value + " not handled in code");
118118
}
119119
}
120120

@@ -153,7 +153,7 @@ public partial class MyBO
153153
set(await ((await (bo.GetOrCreateBO1Async(s, cancellationToken))).GetOrCreateBO2Async(s, cancellationToken)), 1);
154154
break;
155155
default:
156-
throw new Exception("Value " + value + " not handled in code");
156+
throw new NotImplementedException("Value " + value + " not handled in code");
157157
}
158158
}
159159

@@ -187,7 +187,7 @@ public partial class MyBO
187187
(await ((await (bo.GetOrCreateBO1Async(s, cancellationToken))).GetOrCreateBO3Async(s, cancellationToken))).L1 = 1;
188188
break;
189189
default:
190-
throw new Exception("Value " + value + " not handled in code");
190+
throw new NotImplementedException("Value " + value + " not handled in code");
191191
}
192192
}
193193
}

src/NHibernate.Test/Async/QueryTest/DetachedQueryFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ public Dictionary<string, TypedValue> NamedListParams
260260

261261
public override IQuery GetExecutableQuery(ISession session)
262262
{
263-
throw new Exception("The method or operation is not implemented.");
263+
throw new NotImplementedException("The method or operation is not implemented.");
264264
}
265265

266266
public new void CopyTo(IDetachedQuery destination)

src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public void SimpleCriterion_NoAlias()
4747
public static int CompareString(string left, string right, bool textCompare)
4848
{
4949
// could consider calling Microsoft.VisualBasic.CompilerServices.Operators.CompareString
50-
throw new Exception("This is just here to allow us to simulate the VB.Net LINQ expression tree");
50+
throw new InvalidOperationException("This is just here to allow us to simulate the VB.Net LINQ expression tree");
5151
}
5252

5353
[Test]

src/NHibernate.Test/DynamicProxyTests/PeVerifier.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public PeVerifier(string assemblyFileName)
2626
while (!Directory.Exists(Path.Combine(dir, "Tools", "PEVerify")))
2727
{
2828
if (Directory.GetParent(dir) == null)
29-
throw new Exception(string.Format("Could not find Tools/PEVerify directory in ancestor of {0}", _assemlyLocation));
29+
throw new DirectoryNotFoundException(string.Format("Could not find Tools/PEVerify directory in ancestor of {0}", _assemlyLocation));
3030

3131
dir = Directory.GetParent(dir).FullName;
3232
}
@@ -38,7 +38,7 @@ public PeVerifier(string assemblyFileName)
3838
_peVerifyPath = Path.Combine(dir, "Tools", "PEVerify", versionFolder, "PEVerify.exe");
3939

4040
if (!File.Exists(_peVerifyPath))
41-
throw new Exception(string.Format("Could not find PEVerify.exe at {0}", _peVerifyPath));
41+
throw new FileNotFoundException(string.Format("Could not find PEVerify.exe at {0}", _peVerifyPath));
4242
}
4343

4444
public void AssertIsValid()

src/NHibernate.Test/LogSpy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public LogSpy(ILog log, Level level)
1919
logger = log.Logger as Logger;
2020
if (logger == null)
2121
{
22-
throw new Exception("Unable to get the logger");
22+
throw new InvalidOperationException("Unable to get the logger");
2323
}
2424

2525
// Change the log level to DEBUG and temporarily save the previous log level

src/NHibernate.Test/NHSpecificTest/NH2583/Domain.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public static void SetK1(MyBO bo, ISession s, TK value)
153153
bo.K1 = 1;
154154
break;
155155
default:
156-
throw new Exception("Value " + value + " not handled in code");
156+
throw new NotImplementedException("Value " + value + " not handled in code");
157157
}
158158
}
159159

@@ -184,7 +184,7 @@ private static void SetBO1_I(MyBO bo, ISession s, TBO1_I value, Action<MyRef1, i
184184
set(bo.GetOrCreateBO1(s), 1);
185185
break;
186186
default:
187-
throw new Exception("Value " + value + " not handled in code");
187+
throw new NotImplementedException("Value " + value + " not handled in code");
188188
}
189189
}
190190

@@ -220,7 +220,7 @@ private static void SetBO2_J(MyBO bo, ISession s, TBO2_J value, Action<MyRef2, i
220220
set(bo.GetOrCreateBO2(s), 1);
221221
break;
222222
default:
223-
throw new Exception("Value " + value + " not handled in code");
223+
throw new NotImplementedException("Value " + value + " not handled in code");
224224
}
225225
}
226226

@@ -259,7 +259,7 @@ private static void SetBO1_BO2_J(MyBO bo, ISession s, TBO1_BO2_J value, Action<M
259259
set(bo.GetOrCreateBO1(s).GetOrCreateBO2(s), 1);
260260
break;
261261
default:
262-
throw new Exception("Value " + value + " not handled in code");
262+
throw new NotImplementedException("Value " + value + " not handled in code");
263263
}
264264
}
265265

@@ -293,7 +293,7 @@ public static void SetBO1_BO3_L1(MyBO bo, ISession s, TBO1_BO3_L value)
293293
bo.GetOrCreateBO1(s).GetOrCreateBO3(s).L1 = 1;
294294
break;
295295
default:
296-
throw new Exception("Value " + value + " not handled in code");
296+
throw new NotImplementedException("Value " + value + " not handled in code");
297297
}
298298
}
299299
}

src/NHibernate.Test/QueryTest/DetachedQueryFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ public Dictionary<string, TypedValue> NamedListParams
544544

545545
public override IQuery GetExecutableQuery(ISession session)
546546
{
547-
throw new Exception("The method or operation is not implemented.");
547+
throw new NotImplementedException("The method or operation is not implemented.");
548548
}
549549

550550
public new void CopyTo(IDetachedQuery destination)

src/NHibernate/Criterion/Projections.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ public static AggregateProjection Sum(Expression<Func<object>> expression)
452452
/// </summary>
453453
public static string Concat(params string[] strings)
454454
{
455-
throw new Exception("Not to be used directly - use inside QueryOver expression");
455+
throw QueryOver.GetDirectUsageException();
456456
}
457457

458458
internal static IProjection ProcessConcat(MethodCallExpression methodCallExpression)

src/NHibernate/Criterion/ProjectionsExtensions.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ internal static IProjection ProcessDate(System.Linq.Expressions.Expression expre
7070
/// </summary>
7171
public static double Sqrt(this double numericProperty)
7272
{
73-
throw new Exception("Not to be used directly - use inside QueryOver expression");
73+
throw QueryOver.GetDirectUsageException();
7474
}
7575

7676
/// <summary>
@@ -79,7 +79,7 @@ public static double Sqrt(this double numericProperty)
7979
/// </summary>
8080
public static double Sqrt(this int numericProperty)
8181
{
82-
throw new Exception("Not to be used directly - use inside QueryOver expression");
82+
throw QueryOver.GetDirectUsageException();
8383
}
8484

8585
/// <summary>
@@ -88,7 +88,7 @@ public static double Sqrt(this int numericProperty)
8888
/// </summary>
8989
public static double Sqrt(this long numericProperty)
9090
{
91-
throw new Exception("Not to be used directly - use inside QueryOver expression");
91+
throw QueryOver.GetDirectUsageException();
9292
}
9393

9494
/// <summary>
@@ -97,7 +97,7 @@ public static double Sqrt(this long numericProperty)
9797
/// </summary>
9898
public static double Sqrt(this decimal numericProperty)
9999
{
100-
throw new Exception("Not to be used directly - use inside QueryOver expression");
100+
throw QueryOver.GetDirectUsageException();
101101
}
102102

103103
/// <summary>
@@ -106,7 +106,7 @@ public static double Sqrt(this decimal numericProperty)
106106
/// </summary>
107107
public static double Sqrt(this byte numericProperty)
108108
{
109-
throw new Exception("Not to be used directly - use inside QueryOver expression");
109+
throw QueryOver.GetDirectUsageException();
110110
}
111111

112112
internal static IProjection ProcessSqrt(MethodCallExpression methodCallExpression)
@@ -121,7 +121,7 @@ internal static IProjection ProcessSqrt(MethodCallExpression methodCallExpressio
121121
/// </summary>
122122
public static string Lower(this string stringProperty)
123123
{
124-
throw new Exception("Not to be used directly - use inside QueryOver expression");
124+
throw QueryOver.GetDirectUsageException();
125125
}
126126

127127
internal static IProjection ProcessLower(MethodCallExpression methodCallExpression)
@@ -136,7 +136,7 @@ internal static IProjection ProcessLower(MethodCallExpression methodCallExpressi
136136
/// </summary>
137137
public static string Upper(this string stringProperty)
138138
{
139-
throw new Exception("Not to be used directly - use inside QueryOver expression");
139+
throw QueryOver.GetDirectUsageException();
140140
}
141141

142142
internal static IProjection ProcessUpper(MethodCallExpression methodCallExpression)
@@ -151,7 +151,7 @@ internal static IProjection ProcessUpper(MethodCallExpression methodCallExpressi
151151
/// </summary>
152152
public static int Abs(this int numericProperty)
153153
{
154-
throw new Exception("Not to be used directly - use inside QueryOver expression");
154+
throw QueryOver.GetDirectUsageException();
155155
}
156156

157157
internal static IProjection ProcessIntAbs(MethodCallExpression methodCallExpression)
@@ -166,7 +166,7 @@ internal static IProjection ProcessIntAbs(MethodCallExpression methodCallExpress
166166
/// </summary>
167167
public static Int64 Abs(this Int64 numericProperty)
168168
{
169-
throw new Exception("Not to be used directly - use inside QueryOver expression");
169+
throw QueryOver.GetDirectUsageException();
170170
}
171171

172172
internal static IProjection ProcessInt64Abs(MethodCallExpression methodCallExpression)
@@ -195,7 +195,7 @@ internal static IProjection ProcessRound(MethodCallExpression methodCallExpressi
195195
/// </summary>
196196
public static double Abs(this double numericProperty)
197197
{
198-
throw new Exception("Not to be used directly - use inside QueryOver expression");
198+
throw QueryOver.GetDirectUsageException();
199199
}
200200

201201
internal static IProjection ProcessDoubleAbs(MethodCallExpression methodCallExpression)
@@ -210,7 +210,7 @@ internal static IProjection ProcessDoubleAbs(MethodCallExpression methodCallExpr
210210
/// </summary>
211211
public static string TrimStr(this string stringProperty)
212212
{
213-
throw new Exception("Not to be used directly - use inside QueryOver expression");
213+
throw QueryOver.GetDirectUsageException();
214214
}
215215

216216
internal static IProjection ProcessTrimStr(MethodCallExpression methodCallExpression)
@@ -225,7 +225,7 @@ internal static IProjection ProcessTrimStr(MethodCallExpression methodCallExpres
225225
/// </summary>
226226
public static int StrLength(this string stringProperty)
227227
{
228-
throw new Exception("Not to be used directly - use inside QueryOver expression");
228+
throw QueryOver.GetDirectUsageException();
229229
}
230230

231231
internal static IProjection ProcessStrLength(MethodCallExpression methodCallExpression)
@@ -240,7 +240,7 @@ internal static IProjection ProcessStrLength(MethodCallExpression methodCallExpr
240240
/// </summary>
241241
public static int BitLength(this string stringProperty)
242242
{
243-
throw new Exception("Not to be used directly - use inside QueryOver expression");
243+
throw QueryOver.GetDirectUsageException();
244244
}
245245

246246
internal static IProjection ProcessBitLength(MethodCallExpression methodCallExpression)
@@ -255,7 +255,7 @@ internal static IProjection ProcessBitLength(MethodCallExpression methodCallExpr
255255
/// </summary>
256256
public static string Substr(this string stringProperty, int startIndex, int length)
257257
{
258-
throw new Exception("Not to be used directly - use inside QueryOver expression");
258+
throw QueryOver.GetDirectUsageException();
259259
}
260260

261261
internal static IProjection ProcessSubstr(MethodCallExpression methodCallExpression)
@@ -272,7 +272,7 @@ internal static IProjection ProcessSubstr(MethodCallExpression methodCallExpress
272272
/// </summary>
273273
public static int CharIndex(this string stringProperty, string theChar, int startLocation)
274274
{
275-
throw new Exception("Not to be used directly - use inside QueryOver expression");
275+
throw QueryOver.GetDirectUsageException();
276276
}
277277

278278
internal static IProjection ProcessCharIndex(MethodCallExpression methodCallExpression)
@@ -289,7 +289,7 @@ internal static IProjection ProcessCharIndex(MethodCallExpression methodCallExpr
289289
/// </summary>
290290
public static T Coalesce<T>(this T objectProperty, T replaceValueIfIsNull)
291291
{
292-
throw new Exception("Not to be used directly - use inside QueryOver expression");
292+
throw QueryOver.GetDirectUsageException();
293293
}
294294

295295
/// <summary>
@@ -298,7 +298,7 @@ public static T Coalesce<T>(this T objectProperty, T replaceValueIfIsNull)
298298
/// </summary>
299299
public static T? Coalesce<T>(this T? objectProperty, T replaceValueIfIsNull) where T : struct
300300
{
301-
throw new Exception("Not to be used directly - use inside QueryOver expression");
301+
throw QueryOver.GetDirectUsageException();
302302
}
303303

304304
internal static IProjection ProcessCoalesce(MethodCallExpression methodCallExpression)
@@ -314,7 +314,7 @@ internal static IProjection ProcessCoalesce(MethodCallExpression methodCallExpre
314314
/// </summary>
315315
public static int Mod(this int numericProperty, int divisor)
316316
{
317-
throw new Exception("Not to be used directly - use inside QueryOver expression");
317+
throw QueryOver.GetDirectUsageException();
318318
}
319319

320320
internal static IProjection ProcessMod(MethodCallExpression methodCallExpression)

src/NHibernate/Criterion/QueryOver.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ public DetachedCriteria DetachedCriteria
5656
get { return new DetachedCriteria(impl, impl); }
5757
}
5858

59+
internal static Exception GetDirectUsageException()
60+
{
61+
return new InvalidOperationException("Not to be used directly - use inside QueryOver expression");
62+
}
5963
}
6064

6165
[Serializable]

0 commit comments

Comments
 (0)