Archived

This topic is now archived and is closed to further replies.

elis-cool

Exeption Handling...

Recommended Posts

I''m learning from teach yourself in 21 days and the guy is nuts about classes and all the throw, catchs are using classes eg. class OutOfMemory{}; try { someclass name; } catch(OutOfMemory) { cout << "no memory!"; // do more stuff here } Do you guys use classes as ive also seen just numbers and what not throwen... I would assume using classes this way would be alot slower, though you could stick all that generic shit into the classes constructor then just have: catch(OutOfMemory){}

Share this post


Link to post
Share on other sites
Personally i use the STL classes for exception throwing. If i need a more specific case, i derive my own from exception (STL exception base class). When you throw an exception your application should shut down anyway so you shouldn''t worry about speed. At any rate, get into the habit of catching exceptions by reference:


  
try
{
someclass name;
}
catch(OutOfMemory&)
{
cout << "no memory!";
}

Share this post


Link to post
Share on other sites
This is probably from some Java oriented guy. I suggest dropping the book. I think the free online book "Efficient C++" would be much better.

The C++ standard library has standard exception classes defined to replace the likes of your OutofMemory exception class already.

Share this post


Link to post
Share on other sites