How to Catch All Exceptions in C++? Last Updated : 18 Mar, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report In C++, exceptions are objects that indicate you have an error in your program. They are handled by the try-catch block in C++. In this article, we will learn how to catch all the exceptions in C++. Catching All Exceptions in C++To catch all kinds of exceptions in our catch block in C++, we can define the catch block using the catch-all clause - catch (...), Syntaxtry { // code that can raise an exception throw ExceptionType("Error message"); } catch(...){ // catch all type of unknown exceptions }C++ Program to Catch All ExceptionsIn the following example we have used the catch(...) block to catch all kind of unknown exceptions that might occur during the execution of the program. C++ // C++ program to illustrate how to catch all exceptions #include <iostream> #include <stdexcept> using namespace std; int main() { try { // Code that can throw exceptions int x = 10; int y = 0; if (y == 0) throw runtime_error("Divide by zero exception"); int result = x / y; } // catch the excepetion catch (const runtime_error& e) { // Handle divide by zero exception cout << "Exception: " << e.what() << endl; } // Handle all other types of exceptions catch (...) { cout << "An unknown exception occurred" << endl; } return 0; } OutputException: Divide by zero exception Time Complexity: O(1)Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article How to Catch All Exceptions in C++? G gaurav472 Follow Improve Article Tags : C++ Programs C++ cpp-exception CPP Examples Practice Tags : CPP Similar Reads How to Throw and Catch Exceptions in C++? In C++, exception handling is a mechanism that allows us to handle runtime errors and exceptions are unusual conditions that occur at runtime. In this article, we will learn how to throw and catch exceptions in C++. Throw and Catch Exceptions in C++In C++ exceptions can be "thrown" when an error occ 2 min read How to Catch a Specific Exception in C++? In C++, exceptions are runtime anomalies or abnormal conditions that a program encounters during its execution. The process of handling these exceptions is called exception handling. In this article, we will learn how we can catch specific exceptions in C++. Catch a Specific Exception in C++ In C++, 2 min read How to Throw a Custom Exception in C++? In C++, exception handling is done by throwing an exception in a try block and catching it in the catch block. We generally throw the built-in exceptions provided in the <exception> header but we can also create our own custom exceptions.In this article, we will discuss how to throw a custom e 2 min read How to Throw an Exception in C++? In C++, exception handling is a mechanism that allows us to handle runtime errors and exceptions are objects that represent an error that occurs during the execution of a program. In this article, we will learn how to throw an exception in C++. Throw a C++ ExceptionThrowing an exception means sendin 2 min read How to Catch Floating Point Errors in C++? In C++, a part of the code that may throw exceptions is enclosed in try-and-catch blocks to handle them when they arise. We can also use try...catch to catch floating point errors but it involves a bit different approach in comparison to catching standard exceptions. In this article, we will look at 2 min read Like