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

`fail` should support rethrowing an exception object #941

Closed
krader1961 opened this issue Mar 18, 2020 · 1 comment
Closed

`fail` should support rethrowing an exception object #941

krader1961 opened this issue Mar 18, 2020 · 1 comment
Labels
Milestone

Comments

@krader1961
Copy link
Contributor

@krader1961 krader1961 commented Mar 18, 2020

I noticed that this pattern fails with Exception: wrong type of 1'th argument: wrong type: need string, got exception:

try {
    /usr/bin/false
} except e {
    fail e
}

It seems to me it should be possible to re-throw an exception. Yes, you can do fail (to-string $e) but that will lose information if and when exception objects have attributes other than cause. It also violates the DRY principal (don't repeat yourself).

On a closely related note we'll probably want fail to accept options to set the hypothetical attributes that seem likely to be added in the future. As a stepping stone fail it might be useful to augment it accept an optional cause option that can be used instead of the current string argument. Either that or the current mandatory argument could be used but not both at the same time.

@krader1961
Copy link
Contributor Author

@krader1961 krader1961 commented Apr 9, 2020

I see that @hanche proposed re-throwing an exception in this comment.

@xiaq xiaq changed the title `fail` should allow an exception object in addition to a string `fail` should support rethrowing an exception object May 3, 2020
@xiaq xiaq added the A:Language label May 3, 2020
@xiaq xiaq modified the milestones: 0.15, 0.14 May 3, 2020
@xiaq xiaq closed this in 92cb80d May 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.