-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.cpp
71 lines (55 loc) · 2.07 KB
/
error.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "error.h"
#include "scheduler.h"
namespace co
{
const char* co_error_category::name() const throw()
{
return "coroutine_error";
}
std::string co_error_category::message(int v) const
{
switch (v) {
case (int)eCoErrorCode::ec_ok:
return "ok";
case (int)eCoErrorCode::ec_mutex_double_unlock:
return "co_mutex double unlock";
case (int)eCoErrorCode::ec_block_object_locked:
return "block object locked when destructor";
case (int)eCoErrorCode::ec_block_object_waiting:
return "block object was waiting when destructor";
case (int)eCoErrorCode::ec_yield_failed:
return "yield failed";
case (int)eCoErrorCode::ec_swapcontext_failed:
return "swapcontext failed";
case (int)eCoErrorCode::ec_makecontext_failed:
return "makecontext failed";
case (int)eCoErrorCode::ec_iocpinit_failed:
return "iocp init failed";
case (int)eCoErrorCode::ec_protect_stack_failed:
return "protect stack failed";
case (int)eCoErrorCode::ec_std_thread_link_error:
return "std thread link error.\n"
"if static-link use flags: '-Wl,--whole-archive -lpthread -Wl,--no-whole-archive -static' on link step;\n"
"if dynamic-link use flags: '-pthread' on compile step and link step;\n";
case (int)eCoErrorCode::ec_disabled_multi_thread:
return "Unsupport multiply threads. If you want use multiply threads, please cmake libgo without DISABLE_MULTI_THREAD option.";
}
return "";
}
const std::error_category& GetCoErrorCategory()
{
static co_error_category obj;
return obj;
}
std::error_code MakeCoErrorCode(eCoErrorCode code)
{
return std::error_code((int)code, GetCoErrorCategory());
}
void ThrowError(eCoErrorCode code)
{
DebugPrint(dbg_exception, "throw exception %d:%s",
(int)code, GetCoErrorCategory().message((int)code).c_str());
if (std::uncaught_exception()) return ;
throw std::system_error(MakeCoErrorCode(code));
}
} //namespace co