Home > Backend Development > PHP Tutorial > PHP error and exception debugging video tutorial resource sharing

PHP error and exception debugging video tutorial resource sharing

黄舟
Release: 2023-03-15 16:02:02
Original
1682 people have browsed it

"PHP Error and Exception Debugging Video Tutorial" This course mainly explains two parts. It starts with the error module in PHP, explains the common error types in PHP, and analyzes error handling in PHP. Then it explains the new error handling method in the object-oriented process of PHP5 - the exception module. From the shallower to the deeper, it explains exceptions and their practical applications.

PHP error and exception debugging video tutorial resource sharing

Course playback address: http://www.php.cn/course/406.html

The teacher’s teaching style:

The teacher’s lectures are vivid, witty, witty, and touching. A vivid metaphor is like the finishing touch, opening the door to wisdom for students; a well-placed humor brings a knowing smile to students, like drinking a glass of mellow wine, giving people aftertaste and nostalgia; a philosopher's aphorisms, cultural references Proverbs are interspersed from time to time in the narration, giving people thinking and warning.

The more difficult point in this video is the introduction and use of exceptions in PHP:

  1. Exception: The program operation is not consistent with expectations, and Errors are two different concepts!
    2. Throwing and catching exceptions
    3. When there are multiple catch blocks, the base class should be placed later, otherwise the base class will not continue to catch the exception after catching it!
    3. An error occurs first, then an exception occurs, so when writing the api, be sure to turn off display_errors
    4. PHP’s built-in exceptions

error_reporting(-1);
ini_set('display_errors','off');//pdo内置异常类
try {    
$pdo = new PDO('mysql:host=localhost;dbname=mysql', 'brave', '123456');
    var_dump($pdo);    
echo &#39;<hr/>&#39;;    
echo &#39;continue.......&#39;;
} catch (Exception $e) {    
echo $e->getMessage();
}echo &#39;this is a test.......&#39;;echo &#39;<hr/>&#39;;//spl文件读写内置异常类
try {    
$splObj = new SplFileObject(&#39;test.txt&#39;, &#39;r&#39;);    
echo &#39;read file&#39;;
} catch (RuntimeException $e) {    
echo $e->getMessage();
}echo &#39;continue.......&#39;;echo &#39;<hr/>&#39;;
Copy after login

Exception has several Basic properties and methods, including:

message exception message content
code exception code
file file name where the exception was thrown
line line number of the file where the exception was thrown

Commonly used methods are:

getTrace to obtain exception tracking information
getTraceAsString to obtain the string of exception tracing information
getMessage to obtain error information

If necessary, you can Create a custom exception handling class by inheriting the Exception class.

The above is the detailed content of PHP error and exception debugging video tutorial resource sharing. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template