libGimbal 0.1.0
C17-Based Extended Standard Library and Cross-Language Runtime Framework
Loading...
Searching...
No Matches
gbl::Exception Class Referenceabstract
Inheritance diagram for gbl::Exception:
gbl::CallRecord GblCallRecord gbl::StdException< StdType >

Data Structures

class  TryBlock
 

Public Member Functions

 Exception (const CallRecord &record) noexcept
 
 Exception (CallRecord &&record) noexcept
 
virtual const char * what (void) const noexcept
 
virtual const std::exception & asStdException (void) const =0
 
virtual std::exception & asStdException (void)=0
 
template<typename R >
requires (std::is_constructible_v<Result, R> && !std::same_as<Result, R>)
 CallRecord (R resultValue, const char *pMessage=nullptr, GblObject *pObject=nullptr, SourceLocation srcLoc={}) noexcept
 
 CallRecord (Result result, const char *pMessage=nullptr, GblObject *pObject=nullptr, SourceLocation srcLoc={}) noexcept
 
 CallRecord (const GblCallRecord &other)
 
- Public Member Functions inherited from gbl::CallRecord
template<typename R >
requires (std::is_constructible_v<Result, R> && !std::same_as<Result, R>)
 CallRecord (R resultValue, const char *pMessage=nullptr, GblObject *pObject=nullptr, SourceLocation srcLoc={}) noexcept
 
 CallRecord (Result result, const char *pMessage=nullptr, GblObject *pObject=nullptr, SourceLocation srcLoc={}) noexcept
 
 CallRecord (const GblCallRecord &other)
 
Handle * getHandle (void) const
 
Result getResult (void) const
 
const SourceLocationgetSource (void) const
 
const char * getMessage (void) const
 
std::string getSourceString (void) const
 
std::string toString (void) const
 
- Public Member Functions inherited from GblCallRecord
 GBL_ALIGNAS (8) char message[GBL_CTX_RESULT_MSG_BUFFER_SIZE]
 

Static Public Member Functions

static const CallRecordthrowException (const CallRecord &record)
 
static const CallRecordcheckThrow (const CallRecord &record)
 
static const CallRecordcheckThrow (std::invocable auto fn)
 
static CallRecord tryCatchRecord (std::invocable auto fn, SourceLocation loc=SourceLocation(SRC_FILE, nullptr, SRC_LN, SRC_COL)) noexcept
 

Additional Inherited Members

- Data Fields inherited from GblCallRecord
GblSourceLocation srcLocation
 
GBL_RESULT result
 

Detailed Description

Definition at line 13 of file gimbal_exception.hpp.

Constructor & Destructor Documentation

◆ Exception() [1/2]

gbl::Exception::Exception ( const CallRecord record)
inlinenoexcept

Definition at line 18 of file gimbal_exception.hpp.

18 :
19 CallRecord(record) {}

◆ Exception() [2/2]

gbl::Exception::Exception ( CallRecord &&  record)
inlinenoexcept

Definition at line 20 of file gimbal_exception.hpp.

20 :
21 CallRecord(std::move(record)) {}

Member Function Documentation

◆ what()

virtual const char * gbl::Exception::what ( void  ) const
inlinevirtualnoexcept

Definition at line 23 of file gimbal_exception.hpp.

23 {
24 return getMessage();
25 }

◆ throwException()

const CallRecord & gbl::Exception::throwException ( const CallRecord record)
inlinestatic

Definition at line 135 of file gimbal_exception.hpp.

135 {
136 switch(record.getResult().getValue()) {
137 case Result::ErrorUnderflow: throw StdException<std::underflow_error>(record);
138 case Result::ErrorOverflow: throw StdException<std::overflow_error>(record);
139 case Result::ErrorOutOfRange: throw StdException<std::out_of_range>(record);
140 case Result::ErrorInvalidArg: throw StdException<std::invalid_argument>(record);
141 case Result::ErrorMemAlloc:
142 case Result::ErrorMemRealloc: throw StdException<std::bad_alloc>(record);
143 default: throw StdException<std::exception>(record);
144 }
145 return record;
146}

◆ checkThrow() [1/2]

static const CallRecord & gbl::Exception::checkThrow ( const CallRecord record)
inlinestatic

Definition at line 32 of file gimbal_exception.hpp.

32 {
33 if(record.getResult().isError()) {
34 GBL_API_CLEAR_LAST_RECORD();
35 return throwException(record);
36 }
37 return record;
38 }

◆ checkThrow() [2/2]

static const CallRecord & gbl::Exception::checkThrow ( std::invocable auto  fn)
inlinestatic

Definition at line 40 of file gimbal_exception.hpp.

40 {
41 const GblCallRecord* pRecord = nullptr;
42 GblThread_callRecordSet(NULL, NULL);
43 fn();
44 pRecord = GblThread_callRecord(NULL);
45 return Exception::checkThrow(*pRecord);
46 }
Captures a result, its stringified message, and a source context.

◆ tryCatchRecord()

CallRecord gbl::Exception::tryCatchRecord ( std::invocable auto  fn,
SourceLocation  loc = SourceLocation(SRC_FILEnullptrSRC_LNSRC_COL) 
)
inlinestaticnoexcept

Definition at line 112 of file gimbal_exception.hpp.

112 {
113 try {
114 fn();
115 } catch(const Exception& gblExcept) {
116 return gblExcept;
117 } catch(const std::underflow_error& ex) {
118 return { Result::ErrorUnderflow, ex.what() };
119 } catch(const std::overflow_error& ex) {
120 return { Result::ErrorOverflow, ex.what() };
121 } catch(const std::out_of_range& ex) {
122 return { Result::ErrorOutOfRange, ex.what() };
123 } catch(const std::invalid_argument& ex) {
124 return { Result::ErrorInvalidArg, ex.what() };
125 } catch(const std::bad_alloc& ex) {
126 return { Result::ErrorMemAlloc, ex.what() };
127 } catch(const std::exception& stdEx) {
128 return { Result::ErrorUnhandledException, stdEx.what() };
129 } catch(...) {
130 return { Result::ErrorUnhandledException, "Unknown Exception Type!" };
131 }
132 return Result::Success;
133}

◆ CallRecord() [1/3]

template<typename R >
requires (std::is_constructible_v<Result, R> && !std::same_as<Result, R>)
gbl::CallRecord::CallRecord ( R  resultValue,
const char pMessage = nullptr,
GblObject pObject = nullptr,
SourceLocation  srcLoc = {} 
)
inlinenoexcept

Definition at line 46 of file gimbal_call_stack.hpp.

46 {}) noexcept:
47 CallRecord(Result(resultValue), pMessage, pObject, std::move(srcLoc)) {}

◆ CallRecord() [2/3]

gbl::CallRecord::CallRecord ( Result  result,
const char pMessage = nullptr,
GblObject pObject = nullptr,
SourceLocation  srcLoc = {} 
)
inlinenoexcept

Definition at line 49 of file gimbal_call_stack.hpp.

101 {
102 GBL_CALL_RECORD_CONSTRUCT(this, pObject, result.getCode(), srcLoc, "%s", pMessage? pMessage : result.toString());
103}
GBL_RESULT result
Result code from a previous stack frame.

◆ CallRecord() [3/3]

gbl::CallRecord::CallRecord ( const GblCallRecord other)
inline

Definition at line 51 of file gimbal_call_stack.hpp.

51 {
52 memcpy(this, &other, sizeof(GblCallRecord));
53 }

The documentation for this class was generated from the following file: