views:

54

answers:

2

C# noob question...

I'm taking a few arguments in a class constructor to initialize some private variables. What should I do when the data passed in is not what I expect (wrong string length, numbers out of expected range, nonexisting path, stuff like that..)? Throw an exception? Add "everything went ok" flag?

how is it usually done?

+2  A: 

Throw an ArgumentException.

See this related question for more detail:

http://stackoverflow.com/questions/823224/whats-a-good-way-for-a-c-dll-to-return-error-to-the-calling-application

Brian
+1  A: 

Throw an appropriate ArgumentException as the initial state for the class could not be established based on the input.

Brian Rasmussen