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

boundary/break expression plus several examples of custom control structures #3105

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gkepka
Copy link
Contributor

@gkepka gkepka commented Nov 18, 2024

No description provided.

@gkepka gkepka linked an issue Nov 18, 2024 that may be closed by this pull request
{% endtab %}
{% endtabs %}

Since `break` uses an exception to control the execution flow, mixing it with `try`/`catch` can lead to unexpected results:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one looks like a potential huge footgun if someone doesn't notice break throws an exception, so I wanted to mention it. Please notify if the try/catch example is OK and should stay.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try also swallows the control flow because internally it uses try/catch in a non-boundary/break compatible way. It might also be worth explaining how to avoid catching it. (E.g. case e: Exception if !e.isInstanceOf[Break[?]].)

Comment on lines +1123 to +1124
The following example uses a context parameter to store actions to be executed after a block of code is completed. The
`with_defer` function defines a scope in which `defer` can be used to defer execution of actions.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about this because context parameters are not mentioned yet at this point. Maybe the custom control structures section should be moved to a separate page?

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.

Scala book - add documentation on custom control structures
2 participants