Problem during init in constructor - what's next?

C # noob question ...

I am taking multiple arguments in the class constructor to initialize some private variables. What to do when the data is not transferred as I expect (wrong string length, numbers from the expected range, non-existent path, things like that ...)? Throw an exception? Add "everything went fine" flag?

How is this usually done?

0


a source to share


2 answers


Throw an ArgumentException.

See this related question for more details:



What is a good way to return a C # dll to the calling application?

+2




Throw an appropriate ArgumentException because the initial state for the class cannot be set based on input.



+1


a source







All Articles