Skip to content

Commit dbcd198

Browse files
authored
[BUILD] Enable log before throw message in windows (apache#14937)
This PR enables log before throw in windows. The error handling in windows sometimes can be tricky and it is helpful to be able to get as many information as possible. Turning this option on can help us detect possible errors here.
1 parent 1b9678c commit dbcd198

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ if(MSVC)
151151
add_definitions(-D_SCL_SECURE_NO_WARNINGS)
152152
add_definitions(-D_ENABLE_EXTENDED_ALIGNED_STORAGE)
153153
add_definitions(-DNOMINMAX)
154+
# log error before throw as usually windows
155+
# may have issues with stack trace
156+
add_definitions(-DDMLC_LOG_BEFORE_THROW=1)
154157
# regeneration does not work well with msbuild custom rules.
155158
set(CMAKE_SUPPRESS_REGENERATION ON)
156159
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")

include/tvm/runtime/logging.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,11 @@ class LogFatal {
367367
this->lineno_ = lineno;
368368
}
369369
[[noreturn]] TVM_NO_INLINE dmlc::Error Finalize() {
370-
throw InternalError(file_, lineno_, stream_.str());
370+
InternalError error(file_, lineno_, stream_.str());
371+
#if DMLC_LOG_BEFORE_THROW
372+
std::cerr << error.what() << std::endl;
373+
#endif
374+
throw error;
371375
}
372376
std::ostringstream stream_;
373377
std::string file_;

0 commit comments

Comments
 (0)