无法尝试/捕获错误

时间:2014-10-30 20:17:31

标签: asp.net-mvc-4

我正在使用contoso university wb app。但我无法发现错误。

控制器:

public ActionResult Create(Student student)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    studentService.Add(student);
                    studentService.Update(student);
                    return RedirectToAction("Index");
                }
            }
            catch (DataException /* dex */)
            {
                //Log the error (uncomment dex variable name and add a line here to write a log.
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
            }
            return View(student);
        }

这是错误的图像:

https://www.dropbox.com/s/2sw5gor3x2d1lpi/111111.jpg?dl=0

1 个答案:

答案 0 :(得分:1)

其实你正在抓错误! 这就是为什么您的错误消息"Unable to save changes. Try again, and if the problem persists see your system administrator."在浏览器中正常显示,并且没有运行时错误说明发生了异常。