Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


G++ Exception Handling

G++ Exception Handling

G++ Exception Handling

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?


RE: G++ Exception Handling

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.

RE: G++ Exception Handling

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:


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...

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close