| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- //
- // exception.h
- // graphics
- //
- // Created by Sam Jaffe on 7/6/19.
- // Copyright © 2019 Sam Jaffe. All rights reserved.
- //
- #pragma once
- #include <stdexcept>
- #include <string>
- namespace graphics {
- struct file_read_error : std::runtime_error {
- file_read_error(std::string const & file)
- : std::runtime_error("Unable to read file " + file) {}
- file_read_error(std::string const & type, std::string const & file)
- : std::runtime_error("Unable to read " + type + " file " + file) {}
- };
- struct unknown_texture_format : std::runtime_error {
- unknown_texture_format(int components)
- : std::runtime_error("Invalid number of components provided: " +
- std::to_string(components)) {}
- };
- template <typename E> struct unmapped_enum : std::logic_error {
- // TODO (sjaffe): This is just an int cast, which isn't all that helpful.
- // Instead, one might use https://github.com/Neargye/magic_enum
- // or wait for C++ to implement that sort of thing through metaclasses, etc.
- unmapped_enum(E en)
- : std::logic_error("Unknown " + type_name + std::to_string((int)en)) {}
- unmapped_enum(std::string const & str)
- : std::logic_error("Unknown " + type_name + str) {}
- static std::string const type_name;
- };
- template <typename E>
- std::string const unmapped_enum<E>::type_name{typeid(E).name()};
- }
|