exception - STL C++

exception::operator=()

Declaration

exception& exception::operator=(const exception& kqrException);

Description

This is the operator=() function for the exception class.

Header Include

#include <exception>

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 exception& kqrException) {

		// Make an initial assignment
		exception qMyExcept = kqrException;
		cerr << "Message: " << qMyExcept.what() << endl;
		cerr << "Type: " << typeid(qMyExcept).name() << endl;

		// Set it equal to a bad_exception
		qMyExcept = bad_exception();
		cerr << "Message: " << qMyExcept.what() << endl;
		cerr << "Type: " << typeid(qMyExcept).name() << endl;
	}

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

Output

exception::operator=() Output
 

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