A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cplusplus.com/reference/exception/exception/ below:

class

<exception>

std::exception

Standard exception class

Base class for standard exceptions.

All objects thrown by components of the standard library are derived from this class. Therefore, all standard exceptions can be caught by catching this type by reference.

It is declared as:


1
2
3
4
5
6
7
8
class exception {
public:
  exception () throw();
  exception (const exception&) throw();
  exception& operator= (const exception&) throw();
  virtual ~exception() throw();
  virtual const char* what() const throw();
}
1
2
3
4
5
6
7
8
class exception {
public:
  exception () noexcept;
  exception (const exception&) noexcept;
  exception& operator= (const exception&) noexcept;
  virtual ~exception();
  virtual const char* what() const noexcept;
}

Member functions
(constructor)
Construct exception (public member function)
operator=
Copy exception (public member function)
what (virtual)
Get string identifying exception (public member function)
(destructor) (virtual)
Destroy exception (public virtual member function)

Derived types (scattered throughout different library headers)
bad_alloc
Exception thrown on failure allocating memory (class)
bad_cast
Exception thrown on failure to dynamic cast (class)
bad_exception
Exception thrown by unexpected handler (class)
bad_function_call
Exception thrown on bad call (class)
bad_typeid
Exception thrown on typeid of null pointer (class)
bad_weak_ptr
Bad weak pointer (class)
ios_base::failure
Base class for stream exceptions (public member class)
logic_error
Logic error exception (class)
runtime_error
Runtime error exception (class)

Indirectly (through logic_error):
domain_error
Domain error exception (class)
future_error
Future error exception (class)
invalid_argument
Invalid argument exception (class)
length_error
Length error exception (class)
out_of_range
Out-of-range exception (class)

Indirectly (through runtime_error):
overflow_error
Overflow error exception (class)
range_error
Range error exception (class)
system_error
System error exception (class)
underflow_error
Underflow error exception (class)

Indirectly (through bad_alloc):
bad_array_new_length
Exception on bad array length (class)

Indirectly (through system_error, since C++11):
ios_base::failure
Base class for stream exceptions (public member class)

Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// exception example
#include <iostream>       // std::cerr
#include <typeinfo>       // operator typeid
#include <exception>      // std::exception

class Polymorphic {virtual void member(){}};

int main () {
  try
  {
    Polymorphic * pb = 0;
    typeid(*pb);  // throws a bad_typeid exception
  }
  catch (std::exception& e)
  {
    std::cerr << "exception caught: " << e.what() << '\n';
  }
  return 0;
}

Possible output:
exception caught: St10bad_typeid


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4