[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
CppException
Below is an example in which an exception is thrown on purpose and shown on screen:
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
CppException
(C++) Exception
An exception is thrown when 'something goes wrong', e.g. a division by zero. Handling exceptions is called exception handling.Below is an example in which an exception is thrown on purpose and shown on screen:
struct Test { void doThrow() { throw std::exception(); } }; int main() { Test test; try { test.doThrow(); } catch(std::exception& myException) { std::cout << "Catched and recognized the exception" << std::endl; } catch(...) { std::cout << "Catched unknown exception" << std::endl; } std::cout << "Done.." << std::endl; }
- include <iostream>
- include <exception>
Code links
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
