Jump to content
  • Advertisement

Archived

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

jkeppens

inline ... throw()

This topic is 5881 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I was browsing trough some code while I stumbled against a constructor of this form :
    
inline MyClass() throw() {
    _myVar1 = 10;
    _myVar2 = 20;
}
     
My questions are these : a) why make a constructor INLINE? b) what does the throw do? I've worked with error handling before, but here it's after my constructors declaration, haven't seen this before Greetz... [edit] source tag included [edited by - jkeppens on September 7, 2002 6:32:26 PM]

Share this post


Link to post
Share on other sites
Advertisement
quote:
Original post by Fruny
inline constructor - useless and, IIRC illegal.


Why? Sure, you have to be careful about what you inline - and constructors can easily contain more code than you think - but other than that constructors aren't that special, are they?

According to the Standard, default constructors and implicitly generated destructors are public and inline . I'd be very surprised if user-declared inline constructors were somehow illegal.

[edited by - spock on September 8, 2002 7:08:02 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by Fruny
std::unexpected() always call std::terminate().
Huh? What about std::set_unexpected()

Share this post


Link to post
Share on other sites
quote:
Original post by civguy
[quote]Original post by Fruny
std::unexpected() always call std::terminate().
Huh? What about std::set_unexpected()



Doesn''t really make a lot of difference, given that:
Required behavior: An unexpected_handler shall not return. See also 15.5.2.


Whether it be by calling terminate or some other similar function, it has to end the program.

Share this post


Link to post
Share on other sites
I think that if you throw a bad_exception exception from your unexpected exception handler the program does not end because the exception can be caught, I have not tested it though; I have not been able to get my unexpected exception handler called yet, and I don´t think I will continue wasting my time trying to get it. I use visual c++6.0 and as far as I know it ignores exception specifications...

[edited by - spetznaz on September 8, 2002 1:51:46 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by DrPizza
Doesn't really make a lot of difference, given that:
Required behavior: An unexpected_handler shall not return. See also 15.5.2.

Hmm, at least according to Stroustrup, it still can *throw* stuff.

This compiled fine in Dev-C++ (mingw/gcc)

        
#include <stdlib.h>
#include <iostream>
#include <exception>
#include <string>

class E {
public:
std::string _message;
E(const std::string &message) : _message(message) {}
};

class E2 { };

void a(bool throwIllegal) throw(E) {
if (throwIllegal)
throw E2();
else
throw E("normal");
}

void myUnexpectedHandler() throw(E) {
throw E("unexpected");
}

int main(int argc, char *argv[]) {
std::set_unexpected(&myUnexpectedHandler);
try {
a(true);
} catch (E e) {
std::cout << e._message << std::endl;
}

try {
a(false);
} catch (E e) {
std::cout << e._message << std::endl;
}

system("PAUSE");
return 0;
}

And the output was
unexpected
normal

So I can't really agree with this:
quote:
Original post by DrPizza
Whether it be by calling terminate or some other similar function, it has to end the program.


[edited by - civguy on September 8, 2002 2:11:03 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!