66
77#include < concepts>
88#include < cstdint>
9+ #include < source_location>
10+ #include < utility>
911
1012#include " runtime-common/core/runtime-core.h"
1113#include " runtime-light/stdlib/diagnostics/exception-types.h"
6567namespace kphp ::exception {
6668
6769template <std::derived_from<C$Throwable> T>
68- class_instance<T> make_throwable (const string& file, int64_t line, int64_t code, const string& desc) noexcept {
70+ class_instance<T> make_throwable (string file, int64_t line, int64_t code, string desc) noexcept {
6971 auto instance{make_instance<T>()};
7072
7173 auto * instance_ptr{instance.get ()};
72- instance_ptr->$file = file;
74+ instance_ptr->$file = std::move ( file) ;
7375 instance_ptr->$line = line;
7476 instance_ptr->$code = code;
75- instance_ptr->$message = desc;
77+ instance_ptr->$message = std::move ( desc) ;
7678 return instance;
7779}
7880
81+ template <std::derived_from<C$Throwable> T>
82+ class_instance<T> make_throwable (string err_msg, int64_t code = 0 , std::source_location loc = std::source_location::current()) noexcept {
83+ return make_throwable<T>(string{loc.file_name ()}, loc.line (), code, std::move (err_msg));
84+ }
85+
7986} // namespace kphp::exception
8087
8188// ================================================================================================
@@ -87,6 +94,7 @@ T f$_exception_set_location(const T& e, const string& file, int64_t line) noexce
8794 return e;
8895}
8996
90- inline Exception f$err(const string& file, int64_t line, const string& code, const string& desc = {}) noexcept {
91- return kphp::exception::make_throwable<C$Exception>(file, line, 0 , (RuntimeContext::get ().static_SB .clean () << " ERR_" << code << " : " << desc).str ());
97+ inline Exception f$err(string file, int64_t line, const string& code, const string& desc = {}) noexcept {
98+ return kphp::exception::make_throwable<C$Exception>(std::move (file), line, 0 ,
99+ (RuntimeContext::get ().static_SB .clean () << " ERR_" << code << " : " << desc).str ());
92100}
0 commit comments