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)

0 commit comments

Comments
 (0)