[ox] Add makeCatch function
This commit is contained in:
parent
03a1a8abca
commit
90ef5866dd
16
deps/ox/src/ox/std/new.hpp
vendored
16
deps/ox/src/ox/std/new.hpp
vendored
@ -50,6 +50,22 @@ constexpr T *make(Args &&...args) noexcept {
|
||||
#endif
|
||||
}
|
||||
|
||||
template<typename T, typename ...Args>
|
||||
[[nodiscard]]
|
||||
constexpr Result<T*> makeCatch(Args &&...args) noexcept {
|
||||
#ifdef __cpp_exceptions
|
||||
try {
|
||||
return new T(ox::forward<Args>(args)...);
|
||||
} catch (const ox::Exception &ex) {
|
||||
return ex.toError();
|
||||
} catch (...) {
|
||||
return OxError(1, "Allocation or constructor failed");
|
||||
}
|
||||
#else
|
||||
return new T(ox::forward<Args>(args)...);
|
||||
#endif
|
||||
}
|
||||
|
||||
constexpr auto MallocaStackLimit = defines::UseStdLib ? 1024 : 0;
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user