I am working in MVC3 Application. I am struggle to handle exceptions in my controller.
Here My Account controller is,
public ActionResult Register(NewRegister model)
{
if (ModelState.IsValid)
{
if (!IsUserLoginExist(model.Email))
{
AccountServiceHelper.CreatePerson(model);
return RedirectToAction("RegistrationConfirmation", "Account");
}
else
{
ModelState.AddModelError("","Email Address already taken.");
}
}
return View(model);
}
After I validate IsUserLoginExist I am just calling the Helper Class i.e. AccountServiceHelper for consuming a web service method like CreatePerson.
My Helper class looks like this:
public static void CreatePerson(NewRegister model)
{
try
{
try
{
var FirstName = model.FristName;
var LastName = model.LastName;
var Email = model.Email;
var Role = model.Role;
var Password = model.Password;
.....
.....
service.CreatePerson(model);
service.close();
}
catch(Exception e)
{
}
}
catch { }
}
My problem is how can I handle Exception in helper class and return to the controller.
One possibility is to handle the exception at your controller:
and then: