Hi Stackoverflowers,
In designing your class libraries, When you create a method, when do you decide to throw an Exception, or return a boolean.
For example. public class MathHelper
{
public int Divide(int x, int y)
{
if(y == 0)
{
throw new DivideByZeroException("Cannot Divide by Zero");
}
return x / y;
}
}
This is a simple case, but then you start creating more complex methods.
Which do you prefer?
public void Parse(TextReader reader, string delimeter)
{
if(reader == null)
{
throw new ArgumentNullException("The reader cannot be null");
}
if(String.IsNullOrEmpty(delimeter))
{
throw new ArgumentNullException("The delimeter cannot be null");
}
}
public bool Parse(TextReader reader, string delimeter)
{
if(reader == null)
{
logger.Error("Parse failed with null reader");
return false;
}
if(String.IsNullOrEmpty(delimeter))
{
logger.Error("Parse failed with null delimeter");
return false;
}
}