Jump to content
  • Advertisement


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


Exceptions and ASSERT()

This topic is 6497 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

Hello... Can someone please tell me what an exception is? I read some of the other posts going on now, and everyone seems to know what an exception is, but i dont. And what is ASSERT() and what can i use it for? And finally my last question, what is the try/catch/throw method? Some of theese questions might seem a little stupid to you. But actually i am a pretty experienced programmer. At least i think so . I have been programming for about 2 years using DJGPP and Pascal, and i just started Win32 programming with VC++ 6.0. Well, i hope someone will answer some of theese questions... Thanks, René

Share this post

Link to post
Share on other sites
An exception is kinda an error. You use exception handling to catch certain kinds of errors.

In code use use the try {} keyword to check if something goes wrong and then catch to catch the exception.
throw is used to throw an exception that later on can be caught with catch.

This is what I think it is, I didn''t look too closely at it when I read about it beacuse my opinion is that it is a performance killer.

Share this post

Link to post
Share on other sites
not really. exceptions only kill your performance if you actually do have to throw/catch one. Since an exception is usually a fatal error that will stop your program somehow, this is no problem at all.

An assert is like an if statement, however, if it evaluates to false, the program stops, and an error message is generated giving you the line# of the failed assert.

So I''d do something like:

void DoFoo(Foo *fptr) {

if fptr is not null, the assert does nothing. If fptr is null, it trips, and you get an error message.

It''s important to note that asserts compile ONLY in debug mode. When you switch to release, all asserts turn into ; so they don''t rob you of any wasted speed. But also, remember that in release you then don''t have your error checking.

Because of this, asserts are really useful in debugging, to make sure that the arguments to your functions are values that you can work with.

- Remnant
- (Steve Schmitt)

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!