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

Refactor error/exception pages into an "Error handling" page #320

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

Girgias
Copy link
Member

@Girgias Girgias commented Jan 10, 2021

This renames traditional errors to diagnostic errors
Attempts to unify Throwable Errors with Exceptions
Move throw, try, catch, and finally control structures to the control structure section

Feedback on this is very welcome and I'm open to suggestion, as some of the text still needs to be updated/improved.
This is partly based on how Rust talks about error handling.

Some ideas I have also been considering:

  • Split the two section in error-handling.xml into two files in a new subfolder error-handling/

A to-do list of sort:

  • Trim exception page
  • Maybe move extending exception page/trim it?
  • More examples in each specific section.
  • Create a new page in the control structure section for throw

Memo of things to do when this lands:

  • Redirect previous pages to the new ones

@Girgias Girgias changed the title [WIP] Refactor error pages Refactor error/exception pages into an "Error handling" page Jan 13, 2021
@Girgias
Copy link
Member Author

Girgias commented Jan 13, 2021

I think this is now ready for review, I hope I didn't remove any information by splitting it up.

Comment on lines +67 to +75
<warning>
<para>
<classname>Throwable</classname> objects cannot be cloned.
Attempting to <link linkend="language.oop5.cloning">clone</link> such an
object will result in an <classname>Error</classname> being thrown with
the following message:
<literal>Trying to clone an uncloneable object of class Exception</literal>.
</para>
</warning>
Copy link
Member Author

Choose a reason for hiding this comment

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

I wonder if this warning is relevant here? As it would be pretty unusual to clone an exception, and this behaviour is described on their respective docs.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree that this is a generic behavior that is already described in a central location. I see no reason to mention that in every place where it applies. Should the user see such an error, they will be able to find the correct docs through a search.

@Girgias Girgias force-pushed the refactor-error-page branch 3 times, most recently from 9c7354a to 3bee578 Compare January 26, 2021 23:23
</example>

<para>
When the call stack is unwound after a <classname>Throwable</classname> error
Copy link
Contributor

Choose a reason for hiding this comment

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

I think trying to reword this in a way that's more beginner-friendly would be nice. I don't think call stack unwinding is mentioned elsewhere in the docs.

Maybe along the lines of "If there are nested finally blocks, they will be executed in the order they are declared"

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll keep the technical language (as this is copied from the previous document) but will attempt to add a simpler explanation along side it.

language/control-structures/try-catch.xml Outdated Show resolved Hide resolved
<sect1 xml:id="language.error-handling.throwable">
<title><classname>Throwable</classname> errors</title>
<para>
Most errors in PHP are of this type.
Copy link
Contributor

Choose a reason for hiding this comment

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

This statement is highly version-specific (without using set_error_handler, at least).

Copy link
Member Author

Choose a reason for hiding this comment

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

I can add an As of PHP 8, before it, but even in PHP 7 many of the warnings generated by the Engine are catchable Errors

<programlisting role="php">
<![CDATA[
<?php
function exceptions_error_handler($severity, $message, $filename, $lineno) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd argue that doing this is considered best practices by many people. It may be worth calling more attention to this, or adding a best practices section to this document.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure the documentation should decide what are considered best practices, I'll try to emphasis this more however. :-)

language/error-handling.xml Outdated Show resolved Hide resolved
<sect1 xml:id="control-structures.finally" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>finally</title>
<?phpdoc print-version-for="finally"?>
<para>
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like it would be better to front-load the logic of how finally behaves vis a vis throws, returns, yields, exit, etc., perhaps with a bulleted list, so it's easier to reference. Then proceed with a bunch of examples demonstrating it.

language/error-handling.xml Outdated Show resolved Hide resolved
language/operators.xml Outdated Show resolved Hide resolved
@Crell
Copy link
Contributor

Crell commented Feb 15, 2021

Various small issues noted above.

My biggest concern is that this puts exceptions under flow-of-control... but exceptions, as we are told repeatedly, are not meant to be used for flow of control. Yet, they do change the flow of control. My concern is that, without any statement to the contrary, this could tacitly imply that using exceptions the same way you would use if, foreach, or goto is a-OK, when that's very much not the case.

Otherwise, everything else here seems reasonable.

This renames traditional errors to diagnostic errors

Create a page about error handling in PHP describing how to handle
Throwable Errors (Exceptions) and diagnostics.
> Inspired from the Rust docs.

Create dedicated pages for:
 - throw
 - try-catch
 - finally
Usage without it is explained in the following section
Also fix part of the set_error_handler() docs
language/error-handling.xml Outdated Show resolved Hide resolved
Co-authored-by: George Peter Banyard <girgias@php.net>
@afilina
Copy link
Contributor

afilina commented Aug 17, 2021

@Girgias I resolved the outdated comments and provided my feedback on your own questions. I hope this helps to move this PR forward. I also applied the code suggestion with the syntax fix.

@Girgias
Copy link
Member Author

Girgias commented Aug 17, 2021

Thanks, I'll try to get back to this, but I need to sort out HTTP redirection for php-web and rebase, I should have time again in September. :-)

@afilina
Copy link
Contributor

afilina commented Dec 22, 2022

This branch is getting old and has many merge conflicts. Suggestions:

  • If conflicts don't require too much effort to resolve, resolve and merge as-is, fixing later as needed.
  • If too many conflicts, convert it to a checklist ticket, then start new PRs with a smaller change at a time.

@afilina
Copy link
Contributor

afilina commented Aug 2, 2023

@Girgias Is it worth to keep this PR open? This looks like a slice that is too big to be feasible. It can be referred to in a ticket (todo) instead, so that you don't lose sight of some of the wording that might be reusable.

@Girgias
Copy link
Member Author

Girgias commented Aug 2, 2023

@Girgias Is it worth to keep this PR open? This looks like a slice that is too big to be feasible. It can be referred to in a ticket (todo) instead, so that you don't lose sight of some of the wording that might be reusable.

I will try to work on this PR this months as I'm planning to start working on the Migration guide and do more doc works this month (as I also won't have access to my desktop with 24 cores which makes php-src work more annoying)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants