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 calling raise without arguments #3344

Closed
wants to merge 1 commit into from

Conversation

grosser
Copy link
Contributor

@grosser grosser commented Sep 24, 2016

sometimes I just want to raise to stop execution or do something stupid / debug ... would be nice if that worked

... not sure about the test location ... and was unable to run with 0.19.2

bin/crystal spec spec/std/exception_spec.cr
cc: error: /app/src/ext/libcrystal.a: No such file or directory
Error: execution of command failed with code: 1: `cc -o "/root/.cache/crystal/crystal-run-spec.tmp" "${@}"  -rdynamic  -lxml2 -lpcre -lm -lgc -lpthread /app/src/ext/libcrystal.a -levent -lrt -ldl -L/usr/lib -L/usr/local/lib`

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@RX14
Copy link
Member

RX14 commented Sep 25, 2016

@grosser can you try running make std_spec instead of using bin/crystal? I think running make deps would fix the error, but it's recommended to use make when developing the crystal compiler.

@lbguilherme
Copy link
Contributor

I prefer the behavior that raise inside a rescue block would reraise the current exception. IThis is similar to many other languages. Calling raise without a current exception being handled would be a wrong usage, and we could raise some exception type for this. (Calling throw; in C++ when there is no current exception simply aborts the current program)

@RX14
Copy link
Member

RX14 commented Sep 25, 2016

@lbguilherme well I really don't think that this is enough trouble to warrant a language feature:

begin
  raise "ex"
rescue ex
  raise ex if ...
end

@Sija
Copy link
Contributor

Sija commented Sep 25, 2016

@lbguilherme +1, see #3181. Unfortunately, it'd require messing with the global state which is a no-no, especially after 0.19, where globals are gone for good.

@grosser
Copy link
Contributor Author

grosser commented Sep 25, 2016

yeah did not think about re-raise ... raise without argument just working would be confusing / lead people to believe that it re-raised ... so ideally it should fail and say "Raising without argument is not supported, please pass a message or the exception you want to re-raise" ... not sure if that is easy to add ... closing this for now since I think it would make things worse.

@grosser grosser closed this Sep 25, 2016
@grosser grosser deleted the grosser/raise branch September 25, 2016 16:09
@yxhuvud
Copy link
Contributor

yxhuvud commented Sep 25, 2016

One approach would be to take the Ruby route and allow raises without arguments both inside and outside exception handlers, but with different behaviours - raise outside simply raises, whereas inside it will default to the exception being handled.

@yxhuvud
Copy link
Contributor

yxhuvud commented Sep 25, 2016

You only need local state for that - noone would expect raise in a method called from the exception handler to magically know where it was called from.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants