"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.
Course playback address: //m.sbmmt.com/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:
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 '<hr/>'; echo 'continue.......'; } catch (Exception $e) { echo $e->getMessage(); }echo 'this is a test.......';echo '<hr/>';//spl文件读写内置异常类 try { $splObj = new SplFileObject('test.txt', 'r'); echo 'read file'; } catch (RuntimeException $e) { echo $e->getMessage(); }echo 'continue.......';echo '<hr/>';
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!