6#ifndef THEORETICA_IO_ERROR_H
7#define THEORETICA_IO_ERROR_H
9#if defined(THEORETICA_THROW_EXCEPTIONS) || defined(THEORETICA_ONLY_EXCEPTIONS)
11#ifndef THEORETICA_NO_PRINT
75 default:
return "Unknown IO error";
84#if defined(THEORETICA_THROW_EXCEPTIONS) || defined(THEORETICA_ONLY_EXCEPTIONS)
90 std::string func_name;
91 std::string code_file_name;
92 unsigned int code_line;
97 io_exception(IoError a_err,
const std::string& a_func_name,
98 const std::string& a_code_file_name,
unsigned int a_code_line,
const std::string& a_target_file)
99 : err(a_err), func_name(a_func_name), code_file_name(a_code_file_name),
100 code_line(a_code_line), resource(a_target_file) {}
102 ~io_exception() =
default;
104 inline const char* what() const noexcept
override {
110 inline IoError err_code()
const {
116 inline std::string get_function_name()
const {
122 inline std::string get_file_name()
const {
123 return code_file_name;
128 inline unsigned int get_line_number()
const {
134 inline std::string get_resource_id()
const {
139#ifndef THEORETICA_NO_PRINT
142 std::stringstream err_str;
143 err_str << code_file_name <<
"(" << code_line <<
"):";
144 err_str << func_name <<
"(\"" << resource <<
"\"): " <<
to_cstring(err);
145 return err_str.str();
148 inline operator std::string()
const {
152 inline friend std::ostream&
operator<<(std::ostream& out,
const io_exception& obj) {
153 return out << obj.to_string();
164#ifdef THEORETICA_ONLY_EXCEPTIONS
166#define TH_IO_ERROR(F_NAME, RESOURCE_ID, EXCEPTION) \
167 { throw io::io_exception(EXCEPTION, F_NAME, __FILE__, __LINE__, RESOURCE_ID); }
170#elif defined(THEORETICA_THROW_EXCEPTIONS)
172#define TH_IO_ERROR(F_NAME, RESOURCE_ID, EXCEPTION) \
173 { errno = io::to_errno(EXCEPTION); \
174 throw io::io_exception(EXCEPTION, F_NAME, __FILE__, __LINE__, RESOURCE_ID); }
179#define TH_IO_ERROR(F_NAME, RESOURCE_ID, EXCEPTION) \
180 { errno = io::to_errno(EXCEPTION); }
std::ostream & operator<<(std::ostream &os, const hdf5_node &node)
Prints the HDF5 file tree to a stream.
Definition hdf5.h:460
int to_errno(IoError err)
Convert an IoError class enum to conventional errno codes.
Definition error.h:51
IoError
IO error enumeration.
Definition error.h:25
@ FileNotFound
File or directory not found.
@ WriteError
Error occurred while writing to the file or stream.
@ PermissionDenied
Permission denied when accessing the file or directory.
@ FormatError
The file format is invalid or the data is corrupted.
@ EndOfFile
The end of the file was reached unexpectedly during a read operation.
@ ReadError
Error occurred while reading from the file or stream.
const char * to_cstring(IoError err)
Convert an IoError class enum to a string description.
Definition error.h:66
Main namespace of the library which contains all functions and objects.
Definition algebra.h:27
TH_CONSTEXPR Type make_error()
Create a number representing an error state, constructed from a NaN value.
Definition real_analysis.h:1322
std::string to_string(MathError err)
Convert a MathError class enum to a string description.
Definition error.h:72
const char * to_cstring(MathError err)
Convert a MathError class enum to a string description.
Definition error.h:56