#55: When should you throw exception ?

When you make an Assumption of function and it it violates the assumption ,then you might probably need to throw an exception. For instance,Let’s assume that we have function which returns true if the length of List is greater than 50 and false if it is less than 50.Now what if the list is Null?(function Doe not have assumption ) ,this creates the necessary to throw exception  

//This functions assume that you past list item filled with inetgers.
//It is not assumed that list might be null,so here you need to throw exception
private static bool ValidateListLength(List<int>l)
 return l.Count>50;
 throw ;
 return false;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s