exception - STL C++

bad_exception::bad_exception()

Declaration

bad_exception::bad_exception() throw();

Description

This is the constructor for the bad_exception class.

Header Include

#include <exception>

Example

#include <iostream>
#include <exception>

void ThrowBad() throw(std::bad_exception) {
	throw std::bad_exception();
}

int main() {
	using namespace std;

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

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

Output

bad_exception::bad_exception() Output
 

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