2023-05-03 11:06:20 +02:00
== Why is this an issue?
2023-07-04 17:54:34 +02:00
Creating a new https://learn.microsoft.com/en-us/dotnet/api/system.exception[`Exception`] without actually throwing does not achieve the intended purpose.
2020-06-30 12:48:39 +02:00
2023-07-04 17:54:34 +02:00
[source,csharp,diff-id=1,diff-type=noncompliant]
2020-06-30 12:48:39 +02:00
----
if (x < 0)
{
2023-07-04 17:54:34 +02:00
new ArgumentException("x must be nonnegative");
2020-06-30 12:48:39 +02:00
}
----
2023-07-04 17:54:34 +02:00
Ensure to throw the `Exception` with a https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/statements/exception-handling-statements#the-throw-statement[`throw` statement].
2020-06-30 12:48:39 +02:00
2023-07-04 17:54:34 +02:00
[source,csharp,diff-id=1,diff-type=compliant]
2020-06-30 12:48:39 +02:00
----
if (x < 0)
{
2023-07-04 17:54:34 +02:00
throw new ArgumentException("x must be nonnegative");
2020-06-30 12:48:39 +02:00
}
----
2023-07-04 17:54:34 +02:00
== Resources
=== Documentation
* Microsoft Learn - https://learn.microsoft.com/en-us/dotnet/api/system.exception[`Exception` Class]
* Microsoft Learn - https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/statements/exception-handling-statements[Exception-handling statements - `throw`, `try-catch`, `try-finally`, and `try-catch-finally`]
2021-09-20 15:38:42 +02:00
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
include::../highlighting.adoc[]
endif::env-github,rspecator-view[]