exception::bad_exception in C++ with Examples Last Updated : 28 May, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report Standard C++ contains several built-in exception classes, exception::bad_exception is one of them. This is an exception thrown by unexpected handler. Below is the syntax for the same: Header File: include<exception> Syntax: class bad_exception; Return: The exception::bad_exception returns a null terminated character that is used to identify the exception. Note: To make use of exception::bad_exception, one should set up the appropriate try and catch blocks. Below are the examples to understand the implementation of exception::bad_exception in a better way: Program 1 : CPP14 // C++ code for std::bad_exception #include <bits/stdc++.h> using namespace std; void func() { throw; } void geeksforgeeks() throw(bad_exception) { throw runtime_error("test"); } // main method int main() { set_unexpected(func); // try block try { geeksforgeeks(); } // catch block to handle the errors catch (const bad_exception& gfg) { cout << "Caught exception " << gfg.what() << endl; } return 0; } Output: Caught exception std::bad_exception Program 2 : CPP14 // C++ code for std::bad_exception #include <bits/stdc++.h> using namespace std; void gfg() { throw; } void A_Computer_Science_Portal_For_Geeks() throw(bad_exception) { throw runtime_error("test"); } // main method int main() { set_unexpected(gfg); // try block try { A_Computer_Science_Portal_For_Geeks(); } // catch block to handle the errors catch (const bad_exception& a) { cout << "Caught exception " << a.what() << endl; } return 0; } Output: Caught exception std::bad_exception Reference: http://www.cplusplus.com/reference/exception/bad_exception/ Comment More infoAdvertise with us Next Article exception::bad_exception in C++ with Examples B bansal_rtk_ Follow Improve Article Tags : Misc C++ CPP-Functions Practice Tags : CPPMisc Similar Reads ios bad() function in C++ with Examples The bad() method of ios class in C++ is used to check if the stream is has raised any bad error. It means that this function will check if this stream has its badbit set. Syntax: bool bad() const; Parameters: This method does not accept any parameter. Return Value: This method returns true if the st 1 min read exception::what() in C++ with Examples The exception::what() used to get string identifying exception. This function returns a null terminated character sequence that may be used to identify the exception. Below is the syntax for the same: Header File: #include<exception> Syntax: virtual const char* what() const throw(); Return: Th 2 min read functional::bad_function_call in C++ with Examples Standard C++ contains several built-in exception classes, functional::bad_function_call is one of them. This is an exception thrown on bad call. Below is the syntax for the same: Header File: include<functional> Syntax: class bad_function_call; Note: To make use of functional::bad_function_cal 1 min read feclearexcept in C++ with Examples feclearexcept() clears the supported floating-point exceptions represented by excepts. Syntax: int feclearexcept(int excepts); excepts : Bitmask listing of exception flags to clear Return value: The feclearexcept() function returns zero value if all the exceptions were cleared or if excepts is equal 1 min read Built-in Exceptions in Java with examples Types of Exceptions in Java Built-in exceptions are the exceptions that are available in Java libraries. These exceptions are suitable to explain certain error situations. Below is the list of important built-in exceptions in Java. Examples of Built-in Exception:1. Arithmetic exception : It is throw 8 min read Like