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) { ...@@ -741,7 +741,7 @@ inline int LGBM_APIHandleException(const std::string& ex) {
return -1; return -1;
} }
#define API_BEGIN() try { #define API_BEGIN() Log::ResetUseException(true); try {
#define API_END() } \ #define API_END() } \
catch(std::exception& ex) { return LGBM_APIHandleException(ex); } \ catch(std::exception& ex) { return LGBM_APIHandleException(ex); } \
......
...@@ -45,6 +45,10 @@ public: ...@@ -45,6 +45,10 @@ public:
GetLevel() = level; GetLevel() = level;
} }
static void ResetUseException(bool use_ex) {
UseException() = use_ex;
}
static void Debug(const char *format, ...) { static void Debug(const char *format, ...) {
va_list val; va_list val;
va_start(val, format); va_start(val, format);
...@@ -73,7 +77,12 @@ public: ...@@ -73,7 +77,12 @@ public:
vsprintf(str_buf, format, val); vsprintf(str_buf, format, val);
#endif #endif
va_end(val); 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: private:
...@@ -96,6 +105,8 @@ private: ...@@ -96,6 +105,8 @@ private:
static LogLevel& GetLevel() { static thread_local LogLevel level = LogLevel::Info; return level; } static LogLevel& GetLevel() { static thread_local LogLevel level = LogLevel::Info; return level; }
#endif #endif
static bool& UseException() { static bool use_ex = false; return use_ex; }
}; };
} // namespace LightGBM } // namespace LightGBM
......
...@@ -2,22 +2,6 @@ ...@@ -2,22 +2,6 @@
#include <LightGBM/application.h> #include <LightGBM/application.h>
int main(int argc, char** argv) { int main(int argc, char** argv) {
try { LightGBM::Application app(argc, argv);
LightGBM::Application app(argc, argv); app.Run();
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);
}
} }
...@@ -206,6 +206,7 @@ ...@@ -206,6 +206,7 @@
<ClInclude Include="..\include\LightGBM\utils\array_args.h" /> <ClInclude Include="..\include\LightGBM\utils\array_args.h" />
<ClInclude Include="..\include\LightGBM\utils\common.h" /> <ClInclude Include="..\include\LightGBM\utils\common.h" />
<ClInclude Include="..\include\LightGBM\utils\log.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\pipeline_reader.h" />
<ClInclude Include="..\include\LightGBM\utils\random.h" /> <ClInclude Include="..\include\LightGBM\utils\random.h" />
<ClInclude Include="..\include\LightGBM\utils\text_reader.h" /> <ClInclude Include="..\include\LightGBM\utils\text_reader.h" />
......
...@@ -177,6 +177,9 @@ ...@@ -177,6 +177,9 @@
<ClInclude Include="..\src\io\dense_nbits_bin.hpp"> <ClInclude Include="..\src\io\dense_nbits_bin.hpp">
<Filter>src\io</Filter> <Filter>src\io</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\include\LightGBM\utils\openmp_wrapper.h">
<Filter>include\LightGBM\utils</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\src\application\application.cpp"> <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