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

Base exception class for all Magic-related errors. More...

#include <magic_exception.hpp>

Inheritance diagram for Recognition::MagicException:
Collaboration diagram for Recognition::MagicException:

Public Member Functions

 MagicException (const std::string &function, const std::string &error_message)
 Construct MagicException with function name and error message.

Detailed Description

Base exception class for all Magic-related errors.

MagicException inherits from std::runtime_error and provides a common base class for all exceptions thrown by the Magic class. This allows users to catch all Magic errors with a single catch block.

Example

try {
magic.LoadDatabaseFile("/invalid/path");
} catch (const Recognition::MagicException& e) {
std::cerr << "Magic operation failed: " << e.what() << '\n';
}
Base exception class for all Magic-related errors.
Definition magic_exception.hpp:102
See also
std::runtime_error
Since
10.0.0
Examples
magic_examples.cpp.

Constructor & Destructor Documentation

◆ MagicException()

Recognition::MagicException::MagicException ( const std::string & function,
const std::string & error_message )
inline

Construct MagicException with function name and error message.

Creates an exception message in the format:

  • "function failed." (if error_message is empty)
  • "function failed with error_message." (otherwise)
Parameters
[in]functionThe name of the function where the error occurred.
[in]error_messageDescription of the error (optional).
Since
10.0.0

The documentation for this class was generated from the following file: