New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Visual C++ exception message does not print, SIGABRT instead. #11846
Comments
This is what I did to make it work: setTerminate proc() {.noconv.} =
# Remove ourself as a handler, reinstalling the default handler.
setTerminate(nil)
var msg = "Unknown error in unexpected exception handler"
# try:
# raise
# except Exception:
# msg = currException.getStackTrace() & "Error: unhandled exception: " &
# currException.msg & " [" & $currException.name & "]"
# except StdException as e:
# msg = "Error: unhandled cpp exception: " & $e.what()
# except:
# msg = "Error: unhandled unknown cpp exception"
if currException != nil:
msg = currException.getStackTrace() & "Error: unhandled exception: " &
currException.msg & " [" & $currException.name & "]"
when defined(genode):
# stderr not available by default, use the LOG session
echo msg
else:
writeToStdErr msg & "\n"
quit 1 At Line 486 in 572b7c3
I think the issue is that the try:
raise Just does not work with Visual C++ exceptions. But you can just look at the current exception if its there. I am not sure what this try-raise trying to do. I am confused by this. I think this handler was made to also handle c++ native exceptions. But it was not tested on vc++. |
Generating try {
std::rethrow_exception(std::current_exception());
} instead of try {throw;} Works fine when tested on C++ code, but for the Nim code in this issue, msvc gives -
which is again wrong. (on gcc it works). Minimal C++ code for anybody who wants to investigate#include <exception>
#include <iostream>
using namespace std;
void x() {
try {
throw; // does not work in msvc
// rethrow_exception(current_exception()); // works in msvc, but not for https://github.com/nim-lang/Nim/issues/11846
} catch (...) {
cout << "Called by terminate." << endl;
}
exit(-1);
}
int main() {
try {
set_terminate(x);
throw 1;
} catch (string) {
cout << "ABC" << endl;
}
return 0;
}
|
fixed |
@cooldome Still not fixed for me. I get the exception stack trace but not the message. :( |
This change here fixes it: {.emit"#if defined(_MSC_VER) && (_MSC_VER < 1923)".}
#msg = "Error: unhandled unknown cpp exception"
msg = currException.getStackTrace() & "Error: unhandled exception: " &
currException.msg & " [" & $currException.name & "]"
{.emit"#endif".} |
I have updated to the newer visual VC++ and that works as well. I guess we are laving older VC++ in broken state but that's probably fine. |
Test code:
Correct (gcc C):
Correct (gcc C++):
Wrong (Visual C++)
Nim version:
The text was updated successfully, but these errors were encountered: