The C Standard Library
The C++ Standard Library
The C++ STL Library
C++ Programming Resources
Selected Reading
The C++ Standard Library
- C++ Library - <valarray>
- C++ Library - <utility>
- C++ Library - <typeinfo>
- C++ Library - <tuple>
- C++ Library - <thread>
- C++ Library - <string>
- C++ Library - <stdexcept>
- C++ Library - <regex>
- C++ Library - <numeric>
- C++ Library - <new>
- C++ Library - <memory>
- C++ Library - <locale>
- C++ Library - <limits>
- C++ Library - <functional>
- C++ Library - <exception>
- C++ Library - <complex>
- C++ Library - <atomic>
- C++ Library - <streambuf>
- C++ Library - <sstream>
- C++ Library - <ostream>
- C++ Library - <istream>
- C++ Library - <iostream>
- C++ Library - <iosfwd>
- C++ Library - <ios>
- C++ Library - <iomanip>
- C++ Library - <fstream>
- C++ Library - Home
The C++ STL Library
- C++ Library - <iterator>
- C++ Library - <algorithm>
- C++ Library - <vector>
- C++ Library - <unordered_set>
- C++ Library - <unordered_map>
- C++ Library - <stack>
- C++ Library - <set>
- C++ Library - <queue>
- C++ Library - <map>
- C++ Library - <list>
- C++ Library - <forward_list>
- C++ Library - <deque>
- C++ Library - <bitset>
- C++ Library - <array>
C++ Programming Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
C++ Library - <exception>
C++ Library - <exception>
Introduction
It is a standard exception class. All objects thrown by components of the standard pbrary are derived from this class. Therefore, all standard exceptions can be caught by catching this type by reference.
Declaration
Following is the declaration for std::exception.
class exception;
Example
In below example for std::exception.
#include <thread> #include <vector> #include <iostream> #include <atomic> std::atomic_flag lock = ATOMIC_FLAG_INIT; void f(int n) { for (int cnt = 0; cnt < 100; ++cnt) { while (lock.test_and_set(std::memory_order_acquire)) ; std::cout << "Output from thread " << n << ; lock.clear(std::memory_order_release); } } int main() { std::vector<std::thread> v; for (int n = 0; n < 10; ++n) { v.emplace_back(f, n); } for (auto& t : v) { t.join(); } }
Derived types
Sr.No. | Derived types | Definition |
---|---|---|
1 | This exception thrown on failure allocating memory | |
2 | This exception thrown on failure to dynamic cast | |
3 | This an exception thrown by unexpected handler | |
4 | This exception thrown on bad call | |
5 | This exception thrown on typeid of null pointer | |
6 | It is a bad weak pointer | |
7 | It is a base class for stream exceptions | |
8 | It is a logic error exception | |
9 | It is a runtime error exception |
Derived types(through logic_error)
Sr.No. | Derived types | Definition |
---|---|---|
1 | It is a domain error exception | |
2 | It is a future error exception | |
3 | It is an invapd argument exception | |
4 | It is a length error exception | |
5 | It is a out-of-range exception |
Derived types(through runtime_error)
Sr.No. | Derived types | Definition |
---|---|---|
1 | It is an overflow error exception | |
2 | It is a range error exception | |
3 | It is a system error exception | |
4 | It is a underflow error exception |
Derived types(through bad_alloc)
Sr.No. | Derived types | Definition |
---|---|---|
1 | It is an exception on bad array length |
Derived types(through system_error, since C++11)
Sr.No. | Derived types | Definition |
---|---|---|
1 | It is a base class for stream exceptions |
Member functions
Sr.No. | Derived types | Definition |
---|---|---|
1 | It is constructor exception | |
2 | It is a copy exception | |
3 | It is used to get string identifying exception | |
4 | It is a destroy exception |