Why would I ever throw exceptions in code? (except for one specific scenario where I am developing a class library which the consumers of it, will not want / be able to change).
To be more specific, is there any reason to do this:
class EmailSender
{
public void SendEmail(string recipient, string subject, string content)
{
if (string.IsNullOrEmpty(recipient))
{
throw new ArgumentNullException("exception text...");
}
// Send the email
}
}
Instead of this:
class EmailSender
{
public bool SendEmail(string recipient, string subject, string content)
{
bool result = false;
try
{
if (string.IsNullOrEmpty(recipient))
{
logger.Error("Error text...");
}
else
{
// Send the email
result = true;
}
}
catch (Exception ex)
{
logger.Error(ex);
}
return result;
}
}
Take into account that this class is in-house code and not something I am going to ship as a DLL or an open source project.