我的服务类有许多方法,这些方法调用其他服务,而此服务有指定的异常。我想在方法捕获这个指定的异常时抛出我的异常。
try { // call other service } catch(ServiceXxxException serviceEx) { throw new MyException(...); }
但我有很多这样的方法,我不想增加代码。是否可以创建异常属性,如 ExceptionFilterAttribute 对于ASP.NET MVC/Core?
ExceptionFilterAttribute
CustomExceptionFilter] public class HomeController:Controller { //...... } //Over the Action [CustomExceptionFilter] public ActionResult Index() { //....... }
请遵循本文:
https://www.c-sharpcorner.com/UploadFile/0ef46a/exception-filters-in-mvc/