Libmagicxx v5.1.1
A C++ wrapper library over the Magic Number Recognition Library.
Loading...
Searching...
No Matches
magic_exception.hpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: Copyright (c) 2022-2024 Oğuz Toraman <oguz.toraman@tutanota.com> */
2/* SPDX-License-Identifier: LGPL-3.0-only */
3
4#ifndef MAGIC_EXCEPTION_HPP
5#define MAGIC_EXCEPTION_HPP
6
7#include <string>
8#include <stdexcept>
9
10namespace recognition {
11
17class magic_exception : public std::runtime_error {
18public:
19
25 explicit magic_exception(const std::string& error)
26 : std::runtime_error{error}
27 { }
28
36 magic_exception(const std::string& function, const std::string& error)
37 : std::runtime_error{
38 error.empty() ?
39 function + " failed." :
40 function + " failed with " + error + "."
41 }
42 { }
43};
44
45class empty_path final : public magic_exception {
46public:
48 : magic_exception{"path is empty."}
49 { }
50};
51
52class invalid_path final : public magic_exception {
53public:
55 : magic_exception{"path is invalid."}
56 { }
57};
58
59class magic_is_closed final : public magic_exception {
60public:
62 : magic_exception{"magic is closed."}
63 { }
64};
65
66class magic_open_error final : public magic_exception {
67public:
68 explicit magic_open_error(const std::string& error)
69 : magic_exception{"magic_open", error}
70 { }
71};
72
73class magic_load_error final : public magic_exception {
74public:
75 magic_load_error(const std::string& error, const std::string& database_file_path)
76 : magic_exception{"magic_load(" + database_file_path + ")", error}
77 { }
78};
79
80class magic_file_error final : public magic_exception {
81public:
82 magic_file_error(const std::string& error, const std::string& file_path)
83 : magic_exception{"magic_file(" + file_path + ")", error}
84 { }
85};
86
88public:
89 magic_set_flags_error(const std::string& error, const std::string& flag_names)
90 : magic_exception{"magic_set_flags(" + flag_names + ")", error}
91 { }
92};
93
95public:
96 magic_set_param_error(const std::string& error, const std::string& parameter_name, std::size_t value)
97 : magic_exception{"magic_set_param(" + parameter_name + ", " + std::to_string(value) + ")", error}
98 { }
99};
100
101} /* namespace recognition */
102
103#endif /* MAGIC_EXCEPTION_HPP */
Definition magic_exception.hpp:45
empty_path()
Definition magic_exception.hpp:47
Definition magic_exception.hpp:52
invalid_path()
Definition magic_exception.hpp:54
The base class for all exceptions thrown by the magic class.
Definition magic_exception.hpp:17
magic_exception(const std::string &error)
Construct magic_exception with an error message.
Definition magic_exception.hpp:25
magic_exception(const std::string &function, const std::string &error)
Construct magic_exception with an error message and the name of the funtion where the error occurred.
Definition magic_exception.hpp:36
Definition magic_exception.hpp:80
magic_file_error(const std::string &error, const std::string &file_path)
Definition magic_exception.hpp:82
Definition magic_exception.hpp:59
magic_is_closed()
Definition magic_exception.hpp:61
Definition magic_exception.hpp:73
magic_load_error(const std::string &error, const std::string &database_file_path)
Definition magic_exception.hpp:75
Definition magic_exception.hpp:66
magic_open_error(const std::string &error)
Definition magic_exception.hpp:68
Definition magic_exception.hpp:87
magic_set_flags_error(const std::string &error, const std::string &flag_names)
Definition magic_exception.hpp:89
Definition magic_exception.hpp:94
magic_set_param_error(const std::string &error, const std::string &parameter_name, std::size_t value)
Definition magic_exception.hpp:96
Definition magic.hpp:16
std::string to_string(const magic::types_of_files_t &types_of_files, const std::string &type_separator=" -> ", const std::string &file_separator="\n")
Convert the magic::types_of_files_t to string.
Definition magic.cpp:382