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

Exception generated within the .message method of a thrown exception is silently swallowed #4781

Open
p6rt opened this issue Nov 23, 2015 · 3 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Nov 23, 2015

Migrated from rt.perl.org#126717 (status was 'open')

Searchable as RT126717$

@p6rt
Copy link
Author

p6rt commented Nov 23, 2015

From @masak

<masak> m​: class X​::Test is Exception { method message { $.x } }; die
X​::Test.new
<camelia> rakudo-moar : OUTPUT«X​::Test exception produced no message [...]
<masak> ^^ is a bit suboptimal
<masak> if the message method fails for whatever reason, the exception
"produced no message"

It's technically correct that X​::Test produced no message. But it
would be even better if the exception that occurs inside of .message
were thrown in some fashion​:

<masak> m​: class X​::Test is Exception { method message { $.x } };
X​::Test.new.message
<camelia> rakudo-moar : OUTPUT«Method 'x' not found for invocant of
class 'X​::Test' [...]

If we can use our nested exceptions mechanism here somehow, so much
the better. As long as we throw the exception from .message in one way
or another.

@p6rt
Copy link
Author

p6rt commented Nov 24, 2015

From @moritz

Hi,

On Mon Nov 23 12​:13​:07 2015, masak wrote​:

<masak> m​: class X​::Test is Exception { method message { $.x } }; die
X​::Test.new
<camelia> rakudo-moar : OUTPUT«X​::Test exception produced no message [...]
<masak> ^^ is a bit suboptimal
<masak> if the message method fails for whatever reason, the exception
"produced no message"

It's technically correct that X​::Test produced no message. But it
would be even better if the exception that occurs inside of .message
were thrown in some fashion​:

The tricky thing here is avoiding recursion when the exception thrown from .message again produces an exception that throws an exception in its method message.

Also, I'm not sure it's actually better to throw the exception, because people expect to be able to write

try something()
warn $! if $!;
# go on here

and code like this.

I'd argue that throwing an exception from inside Exception.message is a violation of our (so far partially implicit) exception API, and the compiler's response to this is actually undefined behavior. I'd be happy to document it as such.

Cheers,
Moritz

@p6rt
Copy link
Author

p6rt commented Nov 24, 2015

The RT System itself - Status changed from 'new' to 'open'

@p6rt p6rt added the Bug label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant