Photon Common Library 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
io_exceptions.h
Go to the documentation of this file.
1#pragma once
2
3#include "Common/exceptions.h"
4
5#include <string>
6#include <utility>
7#include <format>
8#include <system_error>
9
10namespace ph
11{
12
14{
15public:
16 explicit IOException(const std::string& message);
17 explicit IOException(const char* message);
18};
19
21{
22public:
23 explicit FileIOError(const std::string& message);
24 explicit FileIOError(const char* message);
25 FileIOError(const std::string& message, std::string filename);
26
27 std::string whatStr() const override;
28
29private:
30 std::string m_filename;
31};
32
34{
35public:
37
38 explicit FilesystemError(std::error_code errorCode);
39 FilesystemError(const std::string& message, std::error_code errorCode);
40
41 std::string whatStr() const override;
42
43private:
44 std::error_code m_errorCode;
45};
46
47// In-header Implementations:
48
49inline IOException::IOException(const std::string& message) :
50 RuntimeException(message)
51{}
52
53inline IOException::IOException(const char* const message) :
54 RuntimeException(message)
55{}
56
57inline FileIOError::FileIOError(const std::string& message) :
58 IOException(message),
59 m_filename()
60{}
61
62inline FileIOError::FileIOError(const char* const message) :
63 IOException(message),
64 m_filename()
65{}
66
67inline FileIOError::FileIOError(const std::string& message, std::string filename) :
68 IOException(message),
69 m_filename(std::move(filename))
70{}
71
72inline std::string FileIOError::whatStr() const
73{
74 std::string filenameInfo = m_filename.empty() ? "(unavailable)" : m_filename;
75
76 return std::format("{} | filename <{}>", IOException::whatStr(), filenameInfo);
77}
78
79inline FilesystemError::FilesystemError(std::error_code errorCode)
80 : FilesystemError("", errorCode)
81{}
82
83inline FilesystemError::FilesystemError(const std::string& message, std::error_code errorCode)
84 : IOException(message)
85 , m_errorCode(errorCode)
86{}
87
88inline std::string FilesystemError::whatStr() const
89{
90 auto baseMsg = IOException::whatStr();
91 auto errorCodeMsg = m_errorCode.message();
92 if(errorCodeMsg.empty())
93 {
94 return baseMsg;
95 }
96 else
97 {
98 return std::format("{} ({})", baseMsg, errorCodeMsg);
99 }
100}
101
102}// end namespace ph
Definition io_exceptions.h:21
std::string whatStr() const override
Definition io_exceptions.h:72
FileIOError(const std::string &message)
Definition io_exceptions.h:57
Definition io_exceptions.h:34
FilesystemError(std::error_code errorCode)
Definition io_exceptions.h:79
std::string whatStr() const override
Definition io_exceptions.h:88
Definition io_exceptions.h:14
IOException(const std::string &message)
Definition io_exceptions.h:49
General exception thrown on runtime error.
Definition exceptions.h:21
virtual std::string whatStr() const
Definition exception.cpp:14
The root for all renderer implementations.
Definition assertion.h:9