Skip to content

Commit

Permalink
Disable unknown exception type handling on Windows
Browse files Browse the repository at this point in the history
Summary: These APIs aren't available on Windows, at least with MSVC.

Reviewed By: passy

Differential Revision: D23820257

fbshipit-source-id: bee94980fc683ecc8093f3ad6c8c1313fb003ace
  • Loading branch information
dreiss authored and facebook-github-bot committed Sep 24, 2020
1 parent 6bc2982 commit d4c130a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
9 changes: 8 additions & 1 deletion first-party/fbjni/cxx/fbjni/detail/Exceptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#endif

#include <cstdlib>
#include <cxxabi.h>
#include <ios>
#include <stdexcept>
#include <stdio.h>
Expand All @@ -32,6 +31,10 @@

#include <jni.h>

#ifndef _WIN32
#include <cxxabi.h>
#endif

namespace facebook {
namespace jni {

Expand Down Expand Up @@ -279,13 +282,17 @@ local_ref<JThrowable> convertCppExceptionToJavaException(std::exception_ptr ptr)
} catch (const char* msg) {
current = JUnknownCppException::create(msg);
} catch (...) {
#ifdef _WIN32
current = JUnknownCppException::create();
#else
const std::type_info* tinfo = abi::__cxa_current_exception_type();
if (tinfo) {
std::string msg = std::string("Unknown: ") + tinfo->name();
current = JUnknownCppException::create(msg.c_str());
} else {
current = JUnknownCppException::create();
}
#endif
}

if (addCppStack) {
Expand Down
5 changes: 5 additions & 0 deletions first-party/fbjni/test/FBJniTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,11 @@ public void testHandleNonStdExceptionThrow() {
nativeTestHandleNonStdExceptionThrow();
Fail.failBecauseExceptionWasNotThrown(UnknownCppException.class);
} catch (UnknownCppException ex) {
if (System.getProperty("os.name").startsWith("Windows")) {
// Unknown exception types not supported on Windows.
assertThat(ex.getMessage()).isEqualTo("Unknown");
return;
}
// the actual string is implementation-defined and mangled, but in practice,
// it has the name of the C++ type in it somewhere.
assertThat(ex.getMessage()).startsWith("Unknown: ").contains("NonStdException");
Expand Down

0 comments on commit d4c130a

Please sign in to comment.