-
Notifications
You must be signed in to change notification settings - Fork 40
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
Add exception handling to Ruru #49
Comments
Hm, not entirely sure I'm fond of the syntax - it's very Ruby, and very not Rust. In particular:
As a strawman: handle_exceptions! {
begin {
// ...
} rescue e {
TypeError => /* ... */,
ArgumentError => /* ... */,
_ => /* StandardError */,
} ensure {
// ...
}
} This would significantly reduce the boilerplate, and much more closely mimic the syntax of An alternate strawman is even more handle_exceptions! {
begin {
// ...
} rescue {
TypeError(e) => /* ... */,
ArgumentError(_) => /* ... */,
e => /* StandardError */,
} ensure {
// ...
}
} EDIT: Also, you can always just have three matchers in the same macro - one with |
Does this issue also include unifying the exception types with the existing types? It is totally valid Ruby code to raise an exception as a "return value", e.g. def foo(x)
raise ArgumentException unless x.is_a? Numeric
x + 5
end Perhaps in Rust land, every Ruby method should return a |
I'm in favor of this. I think pub fn eval(string: &str) -> Result<AnyObject, AnyException> {
vm::eval_string_protect(string).map(|v|
AnyObject::from(v)
).map_err(|_|
AnyException::from(vm::errinfo())
)
} Now with PR #88 I've implemented this for I've created an RFC for this subject #91 and I've submitted a PR to add Note: For the |
Also there should be a way to call it without
ensure
(as well asensure
withoutrescue
blocks). Possibly, separate macros are required.The text was updated successfully, but these errors were encountered: