How to use try and catch to catch exceptions in C++
This article mainly introduces "how to use try and catch in C++ to catch exceptions". In daily operation, I believe many people have doubts about how to use try and catch in C++ to catch exceptions. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the questions of "how to use try and catch in C++ to catch exceptions". Next, please follow the editor to study!
Exception handling uses try and catch to catch exceptions
try and catch are the most important C++ keywords. To catch exceptions that may be thrown by statements, place them in try blocks and use catch blocks to handle exceptions that may be thrown by try blocks:
Void somefunc () {try {int* pNumber=new int; * pNumber=999; delete pNumber;} catch (…) / / catches all exceptions {cout