I have the following code:
catch (ServiceException e) { se(e); return View("CreateEdit", vm); }
catch (Exception e) { ex(e); return View("CreateEdit", vm); }
return RedirectToAction("ShowSummary", new {
ds = vm.Meta.DataSourceID
});
protected void se(ServiceException e) {
ModelState.Merge(e.Errors);
}
protected void ex(Exception e) {
Trace.Write(e);
ModelState.AddModelError("", "Database access error: " + e.Message);
}
I would like to change this to something like:
catch (Exception e) { processException(e); return View("CreateEdit", vm); }
Is there a way that I can add code to a processException function that would be able
to check what kind of exception it is and then do action depending on if it is a ServiceException
or just a general exception? I just want to put all my exception handling in one place
and then call it.
You can use the
iskeyword like thisYou can also use a switch statement and test the type of the
ebut IMOisis easier and better