flatten 20260225
This commit is contained in:
71
tjp/core/exception/Exception.hpp
Executable file
71
tjp/core/exception/Exception.hpp
Executable file
@@ -0,0 +1,71 @@
|
||||
// License: Modified MIT (NON-AI)
|
||||
// See the LICENSE file in the root directory for license information.
|
||||
// Copyright 2025 Timothy Prepscius
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Exception.h"
|
||||
#include "../string/String.hpp"
|
||||
#include "../string/StringView.hpp"
|
||||
#include <exception>
|
||||
|
||||
#define TJP_EXCEPTION_BASE ::tjp::core::Exception
|
||||
|
||||
#define DECLARE_EXCEPTION_BASE(e,k) \
|
||||
struct e : k \
|
||||
{ \
|
||||
typedef k Super; \
|
||||
e(const value_type &what) : Super(what) { } \
|
||||
e() { } \
|
||||
} ;\
|
||||
|
||||
#define DECLARE_EXCEPTION_BASE_MSG(e,k,msg) \
|
||||
struct e : k \
|
||||
{ \
|
||||
typedef k Super; \
|
||||
e(const value_type &what) : Super(what) { } \
|
||||
e() : Super(msg) { } \
|
||||
} ;\
|
||||
|
||||
#define DECLARE_EXCEPTION_BASE_MSG_PREFIX(e,k,msg) \
|
||||
struct e : k \
|
||||
{ \
|
||||
static constexpr ::tjp::core::StringView Prefix = msg; \
|
||||
typedef k Super; \
|
||||
e(const value_type &what) : Super(msg ": " + what) { } \
|
||||
e() : Super(msg) { } \
|
||||
} ;\
|
||||
|
||||
#define DECLARE_EXCEPTION_BASE_MSG_PREFIX_ARGS(e,k,msg,...) \
|
||||
struct e : k \
|
||||
{ \
|
||||
static constexpr ::tjp::core::StringView Prefix = msg; \
|
||||
typedef k Super; \
|
||||
e(const value_type &what) : Super(msg ": " + what, __VA_ARGS__) { } \
|
||||
e() : Super(msg, __VA_ARGS__) { } \
|
||||
} ;\
|
||||
|
||||
|
||||
#define DECLARE_EXCEPTION(e) DECLARE_EXCEPTION_BASE(e, TJP_EXCEPTION_BASE)
|
||||
#define DECLARE_EXCEPTION_MESSAGE(e, msg) DECLARE_EXCEPTION_BASE_MSG(e,TJP_EXCEPTION_BASE, msg)
|
||||
|
||||
namespace tjp::core {
|
||||
|
||||
class Exception
|
||||
{
|
||||
public:
|
||||
using value_type = String;
|
||||
|
||||
private:
|
||||
value_type _what;
|
||||
|
||||
public:
|
||||
Exception (const value_type &what) : _what(what) { }
|
||||
Exception () { }
|
||||
virtual ~Exception () { }
|
||||
|
||||
const value_type &what() const throw() { return _what; }
|
||||
value_type &what() throw() { return _what; }
|
||||
} ;
|
||||
|
||||
} // namespace
|
||||
Reference in New Issue
Block a user