Choosing the correct exception type when there is no user attribute

I have a problem with choosing the right type of exception to throw when the expected user attribute is not found (I would prefer one of the existing .NET exceptions).

What do you recommend in this case? Thanks in advance.

Edit:

Here is its context:

[<ExpectedAttribute()>]
let foo args ... = ...

A function foo(which is user defined) is passed to the runtime engine. The runtime should throw an exception if a custom attribute is missing.

+3
source share
3 answers

, System.

, ? ? , ...


, foo: System.ArgumentException, , .

MissingExpectedAttribute.

+3

"InvalidOperationException" "InvalidArgumentException" .

+2

If the object that violates the rules was assigned to the called constructor, method, or property, then an ArgumentException. If the rule violation object was part of your state from a previous operation, and then a method or property was called that insists on the presence of this attribute, InvalidOperation.

+1
source

Source: https://habr.com/ru/post/1759754/


All Articles