Skip to content

Commit

Permalink
result: without exception do not throw when Result Err just abort
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ahayzen-kdab committed Nov 18, 2024
1 parent 7c3fde0 commit 7a0f3f2
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions gen/src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1123,7 +1123,19 @@ fn write_rust_function_shim_impl(
if sig.throws {
out.builtin.rust_error = true;
writeln!(out, " if (error$.ptr) {{");
writeln!(out, "#if defined(RUST_CXX_NO_EXCEPTIONS)");
writeln!(
out,
" const auto msg = static_cast<char const *>(error$.ptr);"
);
writeln!(
out,
" std::fprintf(stderr, \"Error: %s Aborting.\\n\", msg);"
);
writeln!(out, " std::abort();");
writeln!(out, "#else");
writeln!(out, " throw ::rust::impl<::rust::Error>::error(error$);");
writeln!(out, "#endif");
writeln!(out, " }}");
}
if indirect_return {
Expand Down

0 comments on commit 7a0f3f2

Please sign in to comment.