mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2025-12-06 16:56:45 +08:00
upd: try-catch
This commit is contained in:
parent
87279a1299
commit
5a46c3d93e
@ -15,6 +15,7 @@
|
|||||||
#include "libimp/log.h"
|
#include "libimp/log.h"
|
||||||
#include "libimp/codecvt.h"
|
#include "libimp/codecvt.h"
|
||||||
#include "libimp/enum_cast.h"
|
#include "libimp/enum_cast.h"
|
||||||
|
#include "libimp/detect_plat.h"
|
||||||
|
|
||||||
LIBIMP_NAMESPACE_BEG_
|
LIBIMP_NAMESPACE_BEG_
|
||||||
namespace sys {
|
namespace sys {
|
||||||
@ -46,7 +47,7 @@ void error_code(result_code code) noexcept {
|
|||||||
*/
|
*/
|
||||||
std::string error_str(result_code code) noexcept {
|
std::string error_str(result_code code) noexcept {
|
||||||
LIBIMP_LOG_();
|
LIBIMP_LOG_();
|
||||||
try {
|
LIBIMP_TRY {
|
||||||
DWORD err = (DWORD)code.value();
|
DWORD err = (DWORD)code.value();
|
||||||
LPTSTR lpErrText = NULL;
|
LPTSTR lpErrText = NULL;
|
||||||
if (::FormatMessage(
|
if (::FormatMessage(
|
||||||
@ -73,7 +74,7 @@ std::string error_str(result_code code) noexcept {
|
|||||||
std::string ret(len, '\0');
|
std::string ret(len, '\0');
|
||||||
cvt_cstr(lpErrText, msg_len, &ret[0], ret.size());
|
cvt_cstr(lpErrText, msg_len, &ret[0], ret.size());
|
||||||
return ret;
|
return ret;
|
||||||
} catch (std::exception const &e) {
|
} LIBIMP_CATCH(std::exception const &e) {
|
||||||
log.failed(e.what());
|
log.failed(e.what());
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
|
|||||||
@ -11,9 +11,9 @@ LIBIMP_NAMESPACE_BEG_
|
|||||||
namespace sys {
|
namespace sys {
|
||||||
|
|
||||||
std::string error_msg(result_code code) noexcept {
|
std::string error_msg(result_code code) noexcept {
|
||||||
try {
|
LIBIMP_TRY {
|
||||||
return ::fmt::format("[{}, \"{}\"]", code.value(), error_str(code));
|
return ::fmt::format("[{}, \"{}\"]", code.value(), error_str(code));
|
||||||
} catch (...) {
|
} LIBIMP_CATCH(...) {
|
||||||
return error_str(code);
|
return error_str(code);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user