Commit 4d033831 authored by Guolin Ke's avatar Guolin Ke
Browse files

not use exception in command line due to catch-miss of multi-threading exceptions.

parent 12ce2566
......@@ -741,7 +741,7 @@ inline int LGBM_APIHandleException(const std::string& ex) {
return -1;
}
#define API_BEGIN() try {
#define API_BEGIN() Log::ResetUseException(true); try {
#define API_END() } \
catch(std::exception& ex) { return LGBM_APIHandleException(ex); } \
......
......@@ -45,6 +45,10 @@ public:
GetLevel() = level;
}
static void ResetUseException(bool use_ex) {
UseException() = use_ex;
}
static void Debug(const char *format, ...) {
va_list val;
va_start(val, format);
......@@ -73,7 +77,12 @@ public:
vsprintf(str_buf, format, val);
#endif
va_end(val);
throw std::runtime_error(std::string(str_buf));
if (UseException()) {
throw std::runtime_error(std::string(str_buf));
} else {
fprintf(stderr, str_buf);
exit(-1);
}
}
private:
......@@ -96,6 +105,8 @@ private:
static LogLevel& GetLevel() { static thread_local LogLevel level = LogLevel::Info; return level; }
#endif
static bool& UseException() { static bool use_ex = false; return use_ex; }
};
} // namespace LightGBM
......
......@@ -2,22 +2,6 @@
#include <LightGBM/application.h>
int main(int argc, char** argv) {
try {
LightGBM::Application app(argc, argv);
app.Run();
}
catch (const std::exception& ex) {
std::cerr << "Met Exceptions:" << std::endl;
std::cerr << ex.what() << std::endl;
exit(-1);
}
catch (const std::string& ex) {
std::cerr << "Met Exceptions:" << std::endl;
std::cerr << ex << std::endl;
exit(-1);
}
catch (...) {
std::cerr << "Unknown Exceptions" << std::endl;
exit(-1);
}
LightGBM::Application app(argc, argv);
app.Run();
}
......@@ -206,6 +206,7 @@
<ClInclude Include="..\include\LightGBM\utils\array_args.h" />
<ClInclude Include="..\include\LightGBM\utils\common.h" />
<ClInclude Include="..\include\LightGBM\utils\log.h" />
<ClInclude Include="..\include\LightGBM\utils\openmp_wrapper.h" />
<ClInclude Include="..\include\LightGBM\utils\pipeline_reader.h" />
<ClInclude Include="..\include\LightGBM\utils\random.h" />
<ClInclude Include="..\include\LightGBM\utils\text_reader.h" />
......
......@@ -177,6 +177,9 @@
<ClInclude Include="..\src\io\dense_nbits_bin.hpp">
<Filter>src\io</Filter>
</ClInclude>
<ClInclude Include="..\include\LightGBM\utils\openmp_wrapper.h">
<Filter>include\LightGBM\utils</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\src\application\application.cpp">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment