Libmagicxx v10.0.3
A modern C++23 wrapper for libmagic — the library that powers the Unix file command.
Loading...
Searching...
No Matches

Centralized exception throwing utilities. More...

Collaboration diagram for Error Handling:

Functions

template<std::derived_from< MagicException > ExceptionT, typename ResultT, typename... ExceptionArgsT>
requires std::same_as<ResultT, int> || std::same_as<ResultT, bool>
static void Recognition::Magic::MagicPrivate::ThrowExceptionOnFailure (ResultT result, ExceptionArgsT &&... args)
 Centralized error handling template.

Detailed Description

Centralized exception throwing utilities.

Template-based error handling for consistent exception throwing across all MagicPrivate methods.

Function Documentation

◆ ThrowExceptionOnFailure()

template<std::derived_from< MagicException > ExceptionT, typename ResultT, typename... ExceptionArgsT>
requires std::same_as<ResultT, int> || std::same_as<ResultT, bool>
void Recognition::Magic::MagicPrivate::ThrowExceptionOnFailure ( ResultT result,
ExceptionArgsT &&... args )
inlinestatic

Centralized error handling template.

Throws an exception of type ExceptionT if the result indicates failure. Works with both boolean and integer result types.

Template Parameters
ExceptionTException type derived from MagicException.
ResultTEither int or bool.
ExceptionArgsTTypes of exception constructor arguments.
Parameters
[in]resultResult to check (false or LIBMAGIC_ERROR = failure).
[in]argsArguments forwarded to ExceptionT constructor.
Exceptions
ExceptionTIf result is false (bool) or -1 (int).
Usage Examples
// Boolean check - throws if false
// Integer check - throws if -1
// With additional exception arguments
std::filesystem::exists(path), path.string()
);
std::string GetErrorMessage() const noexcept
Retrieve the last error message from libmagic.
Definition magic.cpp:2065
static void ThrowExceptionOnFailure(ResultT result, ExceptionArgsT &&... args)
Centralized error handling template.
Definition magic.cpp:1866
bool IsOpen() const noexcept
Check if instance is open.
Definition magic.cpp:1285
See also
MagicException