Is it good practice to put exception handling in a constructor? -


Is it an exception handling code in a class constructor, or should it be avoided? Should not anyone have the exception-generated code in a manufacturer?

Yes, it is absolutely reasonable how will you and the situation like this:

  class list {public list (integer length) {if (length> 0) {new logic: auto upgrade ("length", "length is not negative"); }         // Okay go! }}  

A list with a negative length is most definitely exceptional, you can not get it back on the collar and think it was successful. What is optional, a checkoff construction is liable Example member function? Yucky

or about it

  class fileParser {public fileParser (string path) {if (! File.Exists (path)) {New FileNotFoundException (path); }         // Okay go! }}  

Again, this is a throw and nothing else is acceptable.


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -