I have some trouble for choosing the right type of exception to throw when an expected custom 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 his the context:
[<ExpectedAttribute()>]
let foo args ... = ...
The function foo (which is user-defined) is passed to a runtime engine. The runtime have to throw an exception if the custom attribute is not present.
If a custom attribute is missing, it is not going to fit a
Systemexception.You could use a System exception, but what is your domain here? And what sort of contract is broken? It matters if this is about serialization or testing or …
Edit, after your
fooaddition: The closest you come with the System exceptions is System.ArgumentException , because your engine is receiving a parameter that does not meet its requirements.But I would define my own
MissingExpectedAttributeexception.