0

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?

Brian
  • 117,631
  • 17
  • 236
  • 300
flamey
  • 2,311
  • 4
  • 33
  • 40

2 Answers2

2

Throw an ArgumentException.

See this related question for more detail:

What's a good way for a c# dll to return error to the calling application?

Community
  • 1
  • 1
Brian
  • 117,631
  • 17
  • 236
  • 300
1

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

Brian Rasmussen
  • 114,645
  • 34
  • 221
  • 317