How to use the exception mode?

Source: Internet
Author: User
When the exception mode is used-PDO: ERRMODE_EXCEPTION (error method 3 in the capture SQL statement in PDO), a PDOException is created in the exception mode and the erorCode attribute is set, it can encapsulate the execution code into a try {...} catch {...} in the statement, uncaptured exceptions will cause the script to be interrupted, and the stack trace will show you the problem! In the first two articles, use the default mode-PDO: ERRMODE_SILENT (capture S in PDO... when the exception mode is used-PDO: ERRMODE_EXCEPTION (error method 3 in the capture SQL statement in PDO), a PDOException is created in the exception mode and the erorCode attribute is set, it can encapsulate the execution code into a try {...} catch {...} in the statement, uncaptured exceptions will cause the script to be interrupted, and the stack trace will show you the problem! In the first two articles, use the default mode-PDO: ERRMODE_SILENT (error method 1 captured in SQL statements in PDO), use the warning mode-PDO :: ERRMODE_WARNING (error method 2 for capturing SQL statements in PDO) describes the default mode and exception mode, so today we will introduce the third method to capture SQL statement errors in PDO ~ The exception mode is also very useful. Compared with traditional PHP-style warnings, you can build your own error handling more clearly, and check the return values of each database call compared to the silent mode and explicitly, the exception mode requires less code/nesting. Division

1. recommendation of 10 SILENT articles

Introduction: function functions are the most basic program structure provided by Python to maximize code reuse and minimize code redundancy. Function type: encapsulate a function code into a function, and you do not need to write it again later. you can call a function to object-oriented: classify and encapsulate the function to make development faster and more...

[Related Q & A recommendations ]:

Javascript-how to encapsulate a piece of javascript code into a method?

Can't statements declaring variables in javascript be encapsulated into functions?

Javascript-Chrome plug-in development, using JSONP cross-origin requests, the callback function is not defined?

Javascript-google analysis of encapsulation code feasibility

Javascript-simple javascript object-oriented programming question: how to encapsulate private attributes and expose public methods?

The above is how to use the exception mode? For more information, see other related articles in the first PHP community!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.