41 lines
1.2 KiB
Plaintext
41 lines
1.2 KiB
Plaintext
== Why is this an issue?
|
|
|
|
Creating a new https://learn.microsoft.com/en-us/dotnet/api/system.exception[`Exception`] without actually throwing does not achieve the intended purpose.
|
|
|
|
[source,csharp,diff-id=1,diff-type=noncompliant]
|
|
----
|
|
if (x < 0)
|
|
{
|
|
new ArgumentException("x must be nonnegative");
|
|
}
|
|
----
|
|
|
|
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].
|
|
|
|
[source,csharp,diff-id=1,diff-type=compliant]
|
|
----
|
|
if (x < 0)
|
|
{
|
|
throw new ArgumentException("x must be nonnegative");
|
|
}
|
|
----
|
|
|
|
== 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`]
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
include::../message.adoc[]
|
|
|
|
include::../highlighting.adoc[]
|
|
|
|
endif::env-github,rspecator-view[]
|