Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow catch behavior to be customized #77

Merged
merged 2 commits into from
Mar 18, 2020
Merged

Allow catch behavior to be customized #77

merged 2 commits into from
Mar 18, 2020

Commits on Mar 18, 2020

  1. Allow catch behavior to be customized

    If the user's cxx::bridge invocation includes any header that defines
    the following function, they get it's behavior as the exception-to-Result
    conversion.
    
        namespace rust::behavior {
        template <typename Try, typename Fail>
        static void trycatch(Try &&func, Fail &&fail) noexcept try {
          func();
        } catch (/* up to you */) {
          fail(/* const char *msg */);
        }
        }
    
    The default behavior is equivalent to:
    
        } catch (const std::exception &e) {
          fail(e.what());
        }
    
    Codebases that use Folly, for example, may be interested in behavior
    like this instead for better type information on the error messages:
    
        } catch (const std::exception &e) {
          fail(folly::exceptionStr(e));
        } catch (...) {
          fail("<unknown exception>");
        }
    dtolnay committed Mar 18, 2020
    Configuration menu
    Copy the full SHA
    3e3e0af View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    0472233 View commit details
    Browse the repository at this point in the history