HttpException
mach::HttpException
Represents an HTTP exception with an associated status code and error message.
Description
Section titled “Description”HttpException is the base class for HTTP exceptions in Mach. Throwing
an HttpException during request processing terminates the current
request and produces an HTTP error response with the exception’s status
code and message.
Use HttpException directly when a specific status code is required, or
use one of Mach’s derived exception types for common HTTP errors.
HttpException derives from std::runtime_error.
Headers
Section titled “Headers”Primary header:
#include <mach/exceptions/HttpException.hpp>Convenience header:
#include <mach/exceptions.hpp>Syntax
Section titled “Syntax”class HttpException : public std::runtime_error {public: HttpException(http::StatusCode status, std::string message);
[[nodiscard]] http::StatusCode status() const noexcept;};Member Functions
Section titled “Member Functions”| Name | Description |
|---|---|
status() |
Returns the HTTP status code associated with the exception. |
what() |
Returns the exception message inherited from std::runtime_error. |
Thread Safety
Section titled “Thread Safety”HttpException is immutable after construction and may be safely
accessed from multiple threads.
Remarks
Section titled “Remarks”The exception owns its error message and associated HTTP status code.
For common HTTP errors, prefer the corresponding derived exception type when one is available.
Example
Section titled “Example”throw mach::HttpException( mach::http::StatusCode::BadRequest, "The request is invalid.");See Also
Section titled “See Also”| Name | Description |
|---|---|
BadRequestException |
Represents an HTTP 400 Bad Request. |
UnauthorizedException |
Represents an HTTP 401 Unauthorized. |
ForbiddenException |
Represents an HTTP 403 Forbidden. |
NotFoundException |
Represents an HTTP 404 Not Found. |
ConflictException |
Represents an HTTP 409 Conflict. |