RAVENNAKIT
Loading...
Searching...
No Matches
exception.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: AGPL-3.0-or-later
2/*
3 * Project: RAVENNAKIT (RAVENNA / AES67 / ST2110-30 SDK)
4 * Copyright (c) 2024-2025 Sound on Digital
5 *
6 * This file is part of RAVENNAKIT.
7 *
8 * RAVENNAKIT is dual-licensed:
9 * 1) Under the terms of the GNU Affero General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version (the "AGPL License"); and
12 * 2) Under a commercial license from Sound on Digital, for customers who
13 * cannot (or do not wish to) comply with the AGPL License terms.
14 *
15 * If you obtained this file under the AGPL License, you may redistribute it
16 * and/or modify it under the terms of the AGPL License. See the LICENSE
17 * file in the project root for details.
18 *
19 * For commercial licensing, support, and other inquiries, please visit:
20 *
21 * https://ravennakit.com
22 *
23 */
24
25#pragma once
26
27#include "platform.hpp"
28
30#include <exception>
31#include <string>
32
36#ifndef RAV_FUNCTION
37 #if RAV_MACOS
38 #define RAV_FUNCTION __PRETTY_FUNCTION__
39 #else
40 #define RAV_FUNCTION static_cast<const char*>(__FUNCTION__)
41 #endif
42#endif
43
44#define RAV_THROW_EXCEPTION(...) throw rav::Exception(fmt::format(__VA_ARGS__), __FILE__, __LINE__, RAV_FUNCTION)
45
46namespace rav {
47
48class Exception: public std::exception {
49 public:
50 explicit Exception(const char* msg, const char* file = nullptr, const int line = -1, const char* function_name = nullptr) :
51 error_(msg), file_(file), line_(line), function_name_(function_name) {}
52
53 explicit Exception(std::string msg, const char* file = nullptr, const int line = -1, const char* function_name = nullptr) :
54 error_(std::move(msg)), file_(file), line_(line), function_name_(function_name) {}
55
59 [[nodiscard]] const char* what() const noexcept override {
60 return error_.c_str();
61 }
62
66 [[nodiscard]] const char* file() const {
67 return file_;
68 }
69
73 [[nodiscard]] int line() const {
74 return line_;
75 }
76
80 [[nodiscard]] const char* function_name() const {
81 return function_name_;
82 }
83
84 private:
85 std::string error_;
86 const char* file_ {};
87 int line_ {};
88 const char* function_name_ {};
89};
90
91} // namespace rav
const char * file() const
Definition exception.hpp:66
Exception(const char *msg, const char *file=nullptr, const int line=-1, const char *function_name=nullptr)
Definition exception.hpp:50
Exception(std::string msg, const char *file=nullptr, const int line=-1, const char *function_name=nullptr)
Definition exception.hpp:53
int line() const
Definition exception.hpp:73
const char * what() const noexcept override
Definition exception.hpp:59
const char * function_name() const
Definition exception.hpp:80