upd: try-catch

This commit is contained in:
mutouyun 2022-11-20 14:33:45 +08:00
parent 87279a1299
commit 5a46c3d93e
2 changed files with 5 additions and 4 deletions

View File

@ -15,6 +15,7 @@
#include "libimp/log.h"
#include "libimp/codecvt.h"
#include "libimp/enum_cast.h"
#include "libimp/detect_plat.h"
LIBIMP_NAMESPACE_BEG_
namespace sys {
@ -46,7 +47,7 @@ void error_code(result_code code) noexcept {
*/
std::string error_str(result_code code) noexcept {
LIBIMP_LOG_();
try {
LIBIMP_TRY {
DWORD err = (DWORD)code.value();
LPTSTR lpErrText = NULL;
if (::FormatMessage(
@ -73,7 +74,7 @@ std::string error_str(result_code code) noexcept {
std::string ret(len, '\0');
cvt_cstr(lpErrText, msg_len, &ret[0], ret.size());
return ret;
} catch (std::exception const &e) {
} LIBIMP_CATCH(std::exception const &e) {
log.failed(e.what());
}
return {};

View File

@ -11,9 +11,9 @@ LIBIMP_NAMESPACE_BEG_
namespace sys {
std::string error_msg(result_code code) noexcept {
try {
LIBIMP_TRY {
return ::fmt::format("[{}, \"{}\"]", code.value(), error_str(code));
} catch (...) {
} LIBIMP_CATCH(...) {
return error_str(code);
}
}