Exceptions
A C++ exception reaches JavaScript as an Error, so try and catch work across the boundary.
parsePercent throws std::out_of_range for a number outside 0 to 100, and std::stoi throws std::invalid_argument for text that is not a number. Both arrive in main.js as an Error.
In a WebAssembly build the message reads <type>: <what()>, and the two parts are also on error.cppType and error.cppMessage. Throwing is the binding-friendly way to report a failure: there are no status codes or out-parameters to check.
Try it
Call squareRoot(-1) outside the try block and see how an uncaught exception shows up.