We Recommend

C++ The Core Language C++ The Core Language
C++: The Core Language is for C programmers transitioning to C++. It's designed to get readers up to speed quickly by covering an essential subset of the language. The subset consists of features without which it's just not C++, and a handful of others that make it a reasonably useful language.


Posted By

yuconner on 08/23/06


Tagged

errors exception


Versions (?)


Who likes this?

1 person has marked this snippet as a favorite

copyleft


try catch example


Published in: C++ 


  1. using namespace std;
  2.  
  3. int main()
  4. {
  5. char *buf;
  6. try
  7. {
  8. buf = new char[512];
  9. if( buf == 0 )
  10. throw "Memory allocation failure!";
  11. }
  12. catch( char * str )
  13. {
  14. cout << "Exception raised: " << str << '\n';
  15. }
  16. // ...
  17. return 0;
  18. }

Report this snippet 

You need to login to post a comment.