crossbind
GitHub

Optional values and exceptions

An empty std::optional arrives as no value, and a C++ exception as an Error.

indexOf returns a std::optional<int>: the index when the letter is there, and no value when the optional is empty, which ?? replaces with a default. Its char parameter takes a one-letter string.

parsePercent throws a std::out_of_range, and main.js catches it as an Error. On the web its message is the exception's type followed by its text.

Try it
Add 'abc' to the list: std::stoi throws an exception of its own. Then look for a letter that occurs twice.
Open in playground
Runs without a compile until the C++, Rust, packages or imports change.
Press Run, or Ctrl+Enter, to run main.js.
Type to search every guide page and section.
↑↓ navigate↵ openesc close