In a method, I want to be able to insert a value into a div which is part of the html document I choose to parse.
public void AddToDiv(string div)
{
//Code to read the html document and look for the div
//(name specified as the parameter of this method).
}
Question is, I could specify a div called "abc" but the html document may not have this div. Fair enough, but what is the difference between me saying:
try
{
//Method logic to parse document for the div
}
catch(ArgumentException ex)
{
// (I wouldn't supress this catch block in production code,
// just omitting body details for simplicity.
}
OR
public void ParseDocument
{
//Logic here...
if(!document.Contains(div)
{
throw new ArgumentException();
}
}
In short, what is the difference between a catch block and saying throw new [ExceptionType here] in the main logic block? How do I decide which is to use?
Thanks