I’m developing in the UI layer of an application and an exception is being thrown in the business layer (or lower) after I make a request. The exception looks like the following
“System.Exception: No Data Returned at …”
Which its obvious someone did a simple:
if (...Rows.Count < 1)
throw new Exception("No Data Returned");
Now in my play ground, should I try to clean this up by trying to rethrow it as a custom exception I can handle specifically as so:
try
{
var myBusinessObject = MyBusinessMethod();
}
catch (Exception ex)
{
if (ex.Message == "No Data Returned")
{
throw new NoDataException(ex.Message);
}
else
{
throw;
}
}
Or is there a more graceful way of handling these.
Note, I do not have the option of changing code outside of the UI layer and I do expect to run into this particular exception often.
Thanks in advance!
This is a little subjective, but I would rather live with the ugliness of handling a
catch (Exception)in my code than worry about what happens if someone changes the error message to something other thanNo Data Returned.