- [ConfigurationElementType(typeof(ErrorMessageSettingHandlerData))]
- publicclassErrorMessageSettingHandler : IExceptionHandler
- {
- publicstringErrorMessage { get; privateset; }
- publicErrorMessageSettingHandler(stringerrorMessage)
- {
- this.ErrorMessage = errorMessage;
- }
- publicException HandleException(Exception exception, Guid handlingInstanceId)
- {
- if(null== ExceptionHandlingContext.Current)
- {
- thrownewInvalidOperationException("...");
- }
- if(string.IsNullOrEmpty(this.ErrorMessage))
- {
- ExceptionHandlingContext.Current.Errors.Add(exception.Message);
- }
- else
- {
- ExceptionHandlingContext.Current.Errors.Add(this.ErrorMessage);
- }
- returnexception;
- }
- }
原文链接:http://www.cnblogs.com/artech/archive/2012/01/10/exception-handling-in-asp-mvc.html