HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
throw_exception.hpp
1// Copyright 2019 Pokitec
2// All rights reserved.
3
4#pragma once
5
6#include <fmt/format.h>
7
8namespace tt {
9
10[[noreturn]] void _throw_invalid_operation_error(char const *source_file, int source_line, std::string message);
11[[noreturn]] void _throw_math_error(char const* source_file, int source_line, std::string message);
12[[noreturn]] void _throw_parse_error(char const* source_file, int source_line, std::string message);
13
14template<typename... Args>
15[[noreturn]] void throw_invalid_operation_error(char const *source_file, int source_line, char const *str, Args &&... args) {
16 _throw_invalid_operation_error(source_file, source_line, fmt::format(str, std::forward<Args>(args)...));
17}
18
19template<typename... Args>
20[[noreturn]] void throw_math_error(char const* source_file, int source_line, char const* str, Args&&... args) {
21 _throw_math_error(source_file, source_line, fmt::format(str, std::forward<Args>(args)...));
22}
23
24template<typename... Args>
25[[noreturn]] void throw_parse_error(char const* source_file, int source_line, char const* str, Args&&... args) {
26 _throw_parse_error(source_file, source_line, fmt::format(str, std::forward<Args>(args)...));
27}
28
29#define TTAURI_THROW_INVALID_OPERATION_ERROR(...) throw_invalid_operation_error(__FILE__, __LINE__, __VA_ARGS__);
30#define TTAURI_THROW_MATH_ERROR(...) throw_math_error(__FILE__, __LINE__, __VA_ARGS__);
31#define TTAURI_THROW_PARSE_ERROR(...) throw_parse_error(__FILE__, __LINE__, __VA_ARGS__);
32
33#define _parse_assert(x) if (!(x)) { TTAURI_THROW_PARSE_ERROR("{}", #x ); }
34#define _parse_assert2(x, ...) if (!(x)) { TTAURI_THROW_PARSE_ERROR(__VA_ARGS__); }
35
36}