
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
How to catch all the exceptions in C++?
Exceptions are the problems which arise at the time of execution of program. It is an event which is thrown at runtime. It protects the code and run the program even after throwing an exception. Exception handling is used to handle the exceptions. We can use try catch block to protect the code.
Catch block is used to catch all types of exception. The keyword “catch” is used to catch exceptions.
Here is an example of catching all the exceptions in C++ language,
Example
#include <iostream> using namespace std; void func(int a) { try { if(a==0) throw 23.33; if(a==1) throw 's'; } catch(...) { cout << "Caught Exception!\n"; } } int main() { func(0); func(1); return 0; }
Output
Here is the output
Caught Exception! Caught Exception!
- Related Articles
- How to catch all JavaScript unhandled exceptions?
- How to catch exceptions in JavaScript?
- How to catch many exceptions at the same time in Kotlin?
- Is it possible to catch multiple Java exceptions in single catch block?
- How to catch multiple exceptions in one line (except block) in Python?
- How to catch all JavaScript errors?
- What is the base class for all exceptions in C#?
- How to create user defined exceptions in C#?
- How do exceptions work in C++
- How to use Try/catch blocks in C#?
- Chained Exceptions in C#
- How to Handle Exceptions in Ruby
- Built-in Exceptions in C#
- What are the custom exceptions in C#?
- How to catch a divide by zero error in C++?

Advertisements