有一种方法可以声明一种“全局处理程序”,它可以在代码的任何位置捕获异常(自定义和默认)。就像一般处理程序会在引发某种异常时进行某种操作,而无需使用可能发生错误的try-except块一样。
感谢您的帮助!
编辑: 我需要一个特别用于自定义Exception类的系统,例如
public IActionResult List() {
// for id in [0..1000] range we collect all corresponding FilialeVM items
var listafiliali = Enumerable
.Range(0, 1000 + 1)
.SelectMany(id => _repoFil
.GetById(id) // items correspond to given id
.Result
.Select(fil => _mapper.Map<FilialeVM>(fil))) // mapped to FilialeVM
.ToList(); // organized as list
// If we have any item in listafiliali, view them, otherwise use default View()
return listafiliali.Any()
? View(listafiliali)
: View();
}
答案 0 :(得分:0)