A collection of custom exception classes written in C#.
System.Object
└── System.Exception
└── System.SystemException
└── Exceptionio.NotFoundException
Class Name | Description | Default Message |
---|---|---|
NotFoundException | The exception that is thrown when a requested method or operation not found. | The method or operation not found. |
Initiate any one of the exception classes:
if (item == null)
{
throw new NotFoundException("Item not found.");
}
An example of handling specific exception:
/// <summary>
/// A filter that converts NotFoundException exceptions into HTTP status code 404, Not Found.
/// </summary>
/// <example>config.Filters.Add(new Xcore.Filters.NotFoundExceptionFilterAttribute());</example>
/// <link>http://blogs.msdn.com/b/youssefm/archive/2012/06/28/error-handling-in-asp-net-webapi.aspx</link>
public class NotFoundExceptionFilterAttribute : ExceptionFilterAttribute, IExceptionFilter
{
public override void OnException(HttpActionExecutedContext context)
{
if (context.Exception is NotFoundException)
{
context.Response = context.Request.CreateResponse(HttpStatusCode.NotFound, new ResponseModel(new MetaModel { Message = string.Format(context.Exception.Message), Code = 404, Success = false }));
}
}
}
Exception.io is released under the MIT license. See LICENSE for details.