diff --git a/include/xo/object2/DRuntimeError.hpp b/include/xo/object2/DRuntimeError.hpp index 9da75c6..c59de59 100644 --- a/include/xo/object2/DRuntimeError.hpp +++ b/include/xo/object2/DRuntimeError.hpp @@ -6,6 +6,7 @@ #pragma once #include "String.hpp" +#include #include namespace xo { @@ -15,20 +16,29 @@ namespace xo { **/ class DRuntimeError { public: + using AGCObject = xo::mm::AGCObject; using ACollector = xo::mm::ACollector; using AAllocator = xo::mm::AAllocator; using ppindentinfo = xo::print::ppindentinfo; public: + /** convenience shortcut.**/ + static obj make(obj mm, + const char * src_fn, + const char * error_descr); + /** create instance using memory from allocator @p mm * @p src_fn identifies the (c++) function/method in which * error detercted. * @p error_descr contains human-readable error message; * will be copied by this function. **/ - DRuntimeError * _make(obj mm, - DString * src_fn, - DString * error_descr); + static DRuntimeError * _make(obj mm, + DString * src_fn, + DString * error_descr); + + DString * src_function() const noexcept { return src_function_; } + DString * error_descr() const noexcept { return error_descr_; } /** @defgroup scm-runtimeerror-printable-facet printable facet **/ ///@{ diff --git a/src/object2/DRuntimeError.cpp b/src/object2/DRuntimeError.cpp index 972bd0c..2b9fa62 100644 --- a/src/object2/DRuntimeError.cpp +++ b/src/object2/DRuntimeError.cpp @@ -3,7 +3,7 @@ * @author Roland Conybeare, Feb 2026 **/ -#include "DRuntimeError.hpp" +#include "RuntimeError.hpp" namespace xo { using xo::mm::AGCObject; @@ -11,6 +11,24 @@ namespace xo { namespace scm { + obj + DRuntimeError::make(obj mm, + const char * src_fn, + const char * error_descr) + { + DRuntimeError * err = DRuntimeError::_make(mm, nullptr, nullptr); + + // pedantic: allocate strings after allocating DRuntimeError instance + + DString * src = DString::from_cstr(mm, src_fn); + DString * err_descr = DString::from_cstr(mm, error_descr); + + err->src_function_ = src; + err->error_descr_ = err_descr; + + return obj(err); + } + DRuntimeError * DRuntimeError::_make(obj mm, DString * src_fn,