exception::what() in C++ with Examples Last Updated : 28 May, 2020 Comments Improve Suggest changes Like Article Like Report 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: The function std::what() return a null terminated character sequence that is used to identify the exception. Note: To make use of std::what(), one should set up the appropriate try and catch blocks. Below are the programs to understand the implementation of std::what() in a better way: Program 1: CPP14 // C++ code for exception::what() #include <bits/stdc++.h> using namespace std; struct gfg : exception { const char* what() const noexcept { return "GeeksforGeeks!! " "A Computer Science" " Portal For Geeks"; } }; // main method int main() { // try block try { throw gfg(); } // catch block to handle the errors catch (exception& gfg1) { cout << gfg1.what(); } return 0; } Output: GeeksforGeeks!! A Computer Science Portal For Geeks Program 2: CPP14 // C++ code for exception::what() #include <bits/stdc++.h> using namespace std; struct geeksforgeeks : exception { const char* what() const noexcept { return "Hey!!"; } }; // main method int main() { // try block try { throw geeksforgeeks(); } // catch block to handle the errors catch (exception& gfg) { cout << gfg.what(); } return 0; } Output: Hey!! Reference: http://www.cplusplus.com/reference/exception/exception/what/ Comment More infoAdvertise with us Next Article exception::what() in C++ with Examples B bansal_rtk_ Follow Improve Article Tags : Misc C++ CPP-Functions Practice Tags : CPPMisc Similar Reads exception::bad_exception in C++ with Examples 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 nu 2 min read ios operator !() function in C++ with Examples The operator!() method of ios class in C++ is used to any error flag of this stream is set. This includes the failbit or the badbit. Syntax: bool operator!() const; Parameters: This method does not accept any parameter. Return Value: This method returns true if any error bit is set of this stream, e 1 min read ios operator() function in C++ with Examples The operator() method of ios class in C++ is used to any error flag of this stream is set. This includes the failbit or the badbit. Syntax: operator void*() const; Parameters: This method does not accept any parameter. Return Value: This method returns a null pointer if any error bit is set of this 1 min read typeid operator in C++ with Examples typeid is an operator in C++. It is used where the dynamic type or runtime type information of an object is needed.It is included in the <typeinfo> library. Hence inorder to use typeid, this library should be included in the program.The typeid expression is an lvalue expression. Syntax: typeid 3 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 Like