Skip to content

Latest commit

 

History

History
75 lines (59 loc) · 1.41 KB

bad-typeid-exception.md

File metadata and controls

75 lines (59 loc) · 1.41 KB
descriptiontitlems.datef1_keywordshelpviewer_keywordsms.assetid
Learn more about: bad_typeid exception
bad_typeid exception
10/04/2019
bad_typeid
bad_typeid_cpp
bad_typeid exception
exceptions [C++], bad_typeid
5963ed58-4ede-4597-957d-f7bbd06299c2

bad_typeid exception

The bad_typeid exception is thrown by the typeid operator when the operand for typeid is a NULL pointer.

Syntax

catch (bad_typeid) statement 

Remarks

The interface for bad_typeid is:

classbad_typeid : publicexception { public:bad_typeid(); bad_typeid(constchar * _Message = "bad typeid"); bad_typeid(const bad_typeid &); virtual~bad_typeid(); bad_typeid& operator=(const bad_typeid&); constchar* what() const; };

The following example shows the typeid operator throwing a bad_typeid exception.

// expre_bad_typeid.cpp// compile with: /EHsc /GR #include<typeinfo> #include<iostream>classA{ public:// object for class needs vtable// for RTTIvirtual~A(); }; usingnamespacestd;intmain() { A* a = NULL; try { cout << typeid(*a).name() << endl; // Error condition } catch (bad_typeid){ cout << "Object is NULL" << endl; } }

Output

Object is NULL 

See also

Run-Time Type Information
Keywords

close