Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any native PHP function which throws an built-in Exception?

Tags:

exception

php

spl

While answering PHP rename() doesn't throws exception on error I was wondering if there are any native PHP functions which throw a built-in Exception, beside the SPL stuff?

like image 675
powtac Avatar asked May 15 '12 19:05

powtac


People also ask

Does PHP have try catch?

The primary method of handling exceptions in PHP is the try-catch. In a nutshell, the try-catch is a code block that can be used to deal with thrown exceptions without interrupting program execution. In other words, you can "try" to execute a block of code, and "catch" any PHP exceptions that are thrown.

Which function handles the code of exception in PHP exception handling?

Try, throw and catch try - A function using an exception should be in a "try" block. If the exception does not trigger, the code will continue as normal. However if the exception triggers, an exception is "thrown" throw - This is how you trigger an exception.

Does throwing an exception return PHP?

When an exception is thrown, code following the statement will not be executed, and PHP will attempt to find the first matching catch block. If an exception is not caught, a PHP Fatal Error will be issued with an " Uncaught Exception ... " message, unless a handler has been defined with set_exception_handler().

What are the exception class functions in PHP?

An exception is an object that describes an error or unexpected behaviour of a PHP script. Exceptions are thrown by many PHP functions and classes. User defined functions and classes can also throw exceptions. Exceptions are a good way to stop a function when it comes across data that it cannot use.


2 Answers

PDO can be configured to throw exceptions

like image 163
dev-null-dweller Avatar answered Sep 29 '22 00:09

dev-null-dweller


Not really. If you read the note on that page you linked:

Note:

Internal PHP functions mainly use Error reporting, only modern Object oriented extensions use exceptions. However, errors can be simply translated to exceptions with ErrorException.

like image 39
animuson Avatar answered Sep 28 '22 23:09

animuson