exception - STL C++

exception::exception()

Declaration

exception::exception();

Description

This is the constructor for the exception class.

Header Include

#include <exception>

Overloads

exception::exception(const exception& kqrCopy);

Example

#include <iostream>
#include <exception>

void ThrowException() throw(std::exception) {
	throw std::exception();
}

int main() {
	using namespace std;

	// The try-catch block allows us to handle exceptions
	try {
		// Call a function to throw an exception
		ThrowException();
	} catch(const std::exception& kqrException) {
		cerr << "Message: " << kqrException.what() << endl;
		cerr << "Type: " << typeid(kqrException).name() << endl;
	}

	// Keep the window open
	std::cin.get();
	return 0;
}

Output

exception::exception() Output
 

© 2007–2024 XoaX.net LLC. All rights reserved.