c# - Method which does nothing or throw Exception -
i have big method, part of checks state of object , throws exception if state invalid. should extract method? new method 'checkstate' nothing or throw exception.
if understand correctly, mean part of method checks state of object , throws exception if invalid.
you further asking whether should move own method(one checks state of object , throws exception of invalid).
the answer is; neither. exception should thrown in "exceptional" circumstances. if enter method , expect object in valid state, use if were.
if occurs unexpected, catch exception , throw "invalidstateexception". (if programmed shouldn't necessary either.)
if enter method , not sure object in valid state, being in invalid 1 not "unexpected" behavior, , should handled differently.
this check method come place. shouldn't throw exception should return boolean, determine next. invalid object in case reasonable, use code handle case check method returns valid_state boolean.
Comments
Post a Comment