Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

G++ Exception Handling

Status
Not open for further replies.

komyg

Programmer
Dec 13, 2005
68
0
0
BR
Hi, I am rather new to C++ programming, but I have worked with Java for sometime.

The thing is that Java has a parent exception class from witch all other exceptions should derive from, therefore when you write a try/catch block you can basically catch any exceptions using the parent exception class.

Does g++ has something similar to this?

Also I've looked around the web seeking the answer to this problem and I found several people saying that Exception Handling on g++ was still under development. Is this still true? Is it safe to use exceptions in g++ or I should wait a while until they are more stable?

Thanks,
Komyg
 
Assuming you're using a recent version of g++, then you can use exceptions just fine.

g++ doesn't have a parent exception class, it is just a compiler. But C++ has one called std::exception. You don't have to use that, but it often makes sense to derive from it or other standard exception classes in <exception>. You should take a look.
 
The problem is that no "predefined" exceptions parent in C++ (as uolj said), so third-party code (possibly) included in your project can throws any class (moreover, any type) exceptions.

Probably the only safe approach is:
Code:
try {
  // processing
} catch (MyExParentClass& e) {
  // your exceptions handler
} catch (...) {
  // unknown exception catched.
}

As far as I know no specific problems with exceptions in g++ implementation...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top