Skip to content

Commit 7a0f3f2

Browse files
committed
result: without exception do not throw when Result Err just abort
For WASM targets the `cc` crate changed to always set `-fno-exceptions`, before only `-fignore-exceptions` was being set elsewhere, so now programs fail to build when using `cxx` if any `throw` or `try ... catch` are used. > error: cannot use 'throw' with exceptions disabled Instead of throwing just abort.
1 parent 7c3fde0 commit 7a0f3f2

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Diff for: gen/src/write.rs

+12
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,19 @@ fn write_rust_function_shim_impl(
11231123
if sig.throws {
11241124
out.builtin.rust_error = true;
11251125
writeln!(out, " if (error$.ptr) {{");
1126+
writeln!(out, "#if defined(RUST_CXX_NO_EXCEPTIONS)");
1127+
writeln!(
1128+
out,
1129+
" const auto msg = static_cast<char const *>(error$.ptr);"
1130+
);
1131+
writeln!(
1132+
out,
1133+
" std::fprintf(stderr, \"Error: %s Aborting.\\n\", msg);"
1134+
);
1135+
writeln!(out, " std::abort();");
1136+
writeln!(out, "#else");
11261137
writeln!(out, " throw ::rust::impl<::rust::Error>::error(error$);");
1138+
writeln!(out, "#endif");
11271139
writeln!(out, " }}");
11281140
}
11291141
if indirect_return {

0 commit comments

Comments
 (0)