捕获控制器中的异常(Catching Exceptions in the Controller)
看起来如果在控制器内发生异常,即使在try-catch块中捕获“异常”,视图引擎也不会进入预期的视图?
或者我在这里遗漏了一些东西:
public ActionResult MyController(int? param1, DateTime? param2) { MyModel model = new MyModel(); try { model = new MyModel(); //AN ERROR HAPPENS HERE (so the code goes to catch the Exception): model.Connection.Initialize(); } catch (Exception ex) { ViewBag.ErrorMessage = ex.Message; } //when I put a break point I get to this following line, however, "MyView" is never displayed!? return PartialView("MyView", model); }It seems like if an Exception occurs inside a controller, the view-engine won't go to the intended view, even if the "exception" is caught inside a try-catch block?
or I'm missing something here:
public ActionResult MyController(int? param1, DateTime? param2) { MyModel model = new MyModel(); try { model = new MyModel(); //AN ERROR HAPPENS HERE (so the code goes to catch the Exception): model.Connection.Initialize(); } catch (Exception ex) { ViewBag.ErrorMessage = ex.Message; } //when I put a break point I get to this following line, however, "MyView" is never displayed!? return PartialView("MyView", model); }最满意答案
您可能会在视图中的某个位置获得另一个例外。 查看浏览器页面上显示的堆栈跟踪并修复它。
You might be getting another exception afterwards, somewhere in your view. Look at the stack trace that displays on the browser page and fix that.
更多推荐
发布评论