5
Postsharp를 사용하여 예외가 throw 된 후 반환 값을 어떻게 설정합니까? Postsharp : 예외 후 반환 값을 설정하는 방법
나는이 일 것이라고 생각 :namespace MvcApplication3.Controllers
{
public class ValuesController : ApiController
{
// GET api/values/5
[MyExceptionHandler]
public string Get(int id)
{
string value = GetValue(id);
return value;
}
private string GetValue(int id)
{
throw new DivideByZeroException();
}
}
[Serializable]
public class MyExceptionHandler : OnExceptionAspect
{
public override void OnException(MethodExecutionArgs args)
{
args.FlowBehavior = FlowBehavior.Continue;
args.ReturnValue = "Error Getting Value";
}
}
}