Photon Common Library 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
exceptions.h
Go to the documentation of this file.
1#pragma once
2
3#include <stdexcept>
4#include <string>
5#include <string_view>
6#include <format>
7#include <type_traits>
8#include <utility>
9
10namespace ph
11{
12
13// Note: When adding new base types, the implementation of `CPhotonException` needs to be updated.
14
15// A convenient "catch all" (including std exceptions) type when handling exceptions
16using Exception = std::exception;
17
20class RuntimeException : public std::runtime_error
21{
22public:
23 explicit RuntimeException(const std::string& message);
24 explicit RuntimeException(const char* message);
25 inline ~RuntimeException() override = default;
26
27 virtual std::string whatStr() const;
28};
29
32class LogicalException : public std::logic_error
33{
34public:
35 explicit LogicalException(const std::string& message);
36 explicit LogicalException(const char* message);
37 inline ~LogicalException() override = default;
38
39 virtual std::string whatStr() const;
40};
41
43{
44public:
46};
47
49{
50public:
51 using NumericException::NumericException;
52};
53
59
65
71
77
78template<typename T>
80 std::is_base_of_v<RuntimeException, T> ||
81 std::is_base_of_v<LogicalException, T>;
82
83template<CPhotonException ExceptionType, typename... Args>
84[[noreturn]]
85inline void throw_formatted(const std::format_string<Args...> msgFormat, Args&&... args)
86{
87 // Intentionally not forwarding to `std::make_format_args` due to P2905R2
88 throw ExceptionType(
89 std::vformat(msgFormat.get(), std::make_format_args(args...)));
90}
91
92}// end namespace ph
Definition exceptions.h:61
Definition exceptions.h:67
General exception thrown on logical error.
Definition exceptions.h:33
LogicalException(const std::string &message)
Definition exception.cpp:19
~LogicalException() override=default
virtual std::string whatStr() const
Definition exception.cpp:27
Definition exceptions.h:43
Definition exceptions.h:73
Definition exceptions.h:49
General exception thrown on runtime error.
Definition exceptions.h:21
RuntimeException(const std::string &message)
Definition exception.cpp:6
virtual std::string whatStr() const
Definition exception.cpp:14
~RuntimeException() override=default
Definition exceptions.h:55
Definition exceptions.h:79
The root for all renderer implementations.
Definition assertion.h:9
std::exception Exception
Definition exceptions.h:16
void throw_formatted(const std::format_string< Args... > msgFormat, Args &&... args)
Definition exceptions.h:85