php / php/doc-en

Document difference between error and exception

Open Beginner friendly
#5,816 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
XML
Stars
596
Forks
890
Avg merge
1d 15h
Merged PRs (30d)
55

Description

Affected page

https://www.php.net/manual/en/reserved.exceptions.php

Current issue

From https://www.php.net/manual/en/class.error.php and https://www.php.net/manual/en/class.exception.php, it seems that Error is thrown by PHP and Exception is for userland code:

Exception is the base class for all user exceptions.

Error is the base class for all internal PHP errors.

This is not accurate and not complete.

Suggested improvement

PHP also throws Exception subclasses. But the semantic meaning is different, apparently.

https://github.com/php/policies/blob/main/coding-standards-and-naming.rst#throwables

The Error hierarchy MUST NOT be used for errors that are expected to be thrown (and caught) during normal operation of a PHP program.

As an example, a parsing function that is expected to be used with untrusted input must not throw an Error if the input is malformed. Similarly a function that interacts with the network must not throw an Error if the network operation fails. Any Error that is thrown should usually result in a reasonably obvious fix in the PHP program.

Tim also said that Error is not supposed to be caught, only Exception is.

Additional context (optional)

No response

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the affected page, reserved.exceptions.php, and compare its wording with class.error.php and class.exception.php. Read the linked PHP throwable coding standards for the intended distinction, then revise the explanation so it accurately describes when Error and Exception subclasses are used and verify the documentation links and examples.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.