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 Errno#errno_message getter #6702
Conversation
I noticed that I override the `message` method in Exception so I needed to rename it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not.
Perhaps this should be a method instead of a class method |
Once we make the error hierarchy independent of the OS, will this still be here? I don't quite understand the use case. |
@RX14 In the end there isn't really a difference and the other methods are also already class methods. @asterite Yes I think it will still be here. The use case is just that when I for example read a file and an error happens, that I can print the reason why the file couldn't be read. begin
File.read("a")
rescue ex : Errno
puts ex
end and it would print |
@r00ster91 then let's save |
Hm, never mind, the name collides with |
@asterite Hmm so we always save the last raised errno message in |
What would be an example for this? Errno gets re-written each time there's an error, so it only makes sense to reference the last one. With that you could do: begin
File.read("a")
rescue ex : Errno
puts ex.errno_message
end But more specifically, why don't you do: begin
File.read("a")
rescue ex
puts "Can't read file a"
end I don't think |
You could always just call |
I prefer to give the user specific information why the program couldn't read the file. Because just this is IMO not very helpful to solve the problem. But okay I will change it to a getter then. I agree. In the end when really need it, I could just call |
This adds
Errno#errno_message
getter which returns the last raised errno message.Usecase:
I want to print the error message from errno in my application just like this:
No such file or directory
instead of this:Unhandled exception: some_call: No such file or directory (Errno)
.