rspec/rules/S3871/csharp/rule.adoc

31 lines
699 B
Plaintext
Raw Normal View History

The point of having custom exception types is to convey more information than is available in standard types. But custom exception types must be `public` for that to work.
If a method throws a non-public exception, the best you can do on the caller's side is to `catch` the closest `public` base of the class. However, you lose all the information that the new exception type carries.
== Noncompliant Code Example
[source,csharp]
----
internal class MyException : Exception // Noncompliant
{
// ...
}
----
== Compliant Solution
[source,csharp]
----
public class MyException : Exception
{
// ...
}
----
include::../exceptions.adoc[]
2022-11-07 10:01:24 +01:00
include::../see.adoc[]
2022-11-07 10:01:24 +01:00
include::../rspecator.adoc[]