-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 Crystal::System.panic
#14733
Add Crystal::System.panic
#14733
Conversation
Prints a system error message on the standard error then exits with an error status. Raising an exception should always be preferred but there are a few cases where we can't allocate any memory (e.g. stop the world) and still need to fail when reaching a system error.
I'm wondering if we could simplify the implementation a bit? The code seems to be mostly identical across platforms with the only difference in retrieving the error message allocation-free. |
@straight-shoota You're right. I thought I couldn't abstract a method without allocating... but all I had to do was yield. The method also takes an explicit Note: a follow-up PR will introduce |
Why is this under the Some languages like go have |
It's a low level primitive for stdlib implmentations. It's probably not very practical for user code. Error handling is usually intended to work with exceptions. And |
That makes sense. Thanks for the explanation. |
Prints a system error message on the standard error then exits with an error status. Raising an exception should always be preferred but there are a few cases where we can't allocate any memory (e.g. stop the world) and still need to fail when reaching a system error.
Extracted from #14729