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

stop using "try ... catch" operators #5

Open
torbengb opened this issue Oct 2, 2020 · 0 comments
Open

stop using "try ... catch" operators #5

torbengb opened this issue Oct 2, 2020 · 0 comments
Assignees
Labels
3prio low "someday" functionality New feature or request

Comments

@torbengb
Copy link
Owner

torbengb commented Oct 2, 2020

stop using "try ... catch" operators,
see https://phpdelusions.net/top#try_catch

Catching an exception only to report it is a sure overkill. Simply because uncaught exception is a fatal error already, and it will be reported by itself. Without that blunt try/catch/die sequence, making your code much cleaner.

and https://phpdelusions.net/pdo_examples/insert

Important! You don't have to check the result of execute() (as it is often shown in low-quality tutorials). Such a condition will make no sense, as in case of error, a PDOException will be thrown and the script execution will be terminated, which means such a condition will never reach the else part.
Neither a try ... catch operator should be used, unless you have a specific scenario to handle the error, such as a transaction rollback shown below. Please see the article about error reporting for the details.

@torbengb torbengb added the functionality New feature or request label Oct 2, 2020
@torbengb torbengb self-assigned this Oct 2, 2020
@torbengb torbengb added the 3prio low "someday" label Oct 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3prio low "someday" functionality New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant