Skip to main content
GameDev.net gamedev.net
🔒 Locked

exceptions: slow?

Started by amish1234 Jan 29, 2004 at 1:38 AM 3 replies 400+ views
Original Post
amish1234
amish1234
For some reason, exceptions are used a lot more in Java than C++. (They use java at my college). My TA was saying that exceptions are very expensive to use. Is the same true in C++? Does it really matter that they''re expensive? I mean, you only throw them when your program is about to blow up anyway. Also, why is it that exceptions are seen in Java a lot more than C++? ___________________________________________________________ Proceeding on a brutal rampage is the obvious choice. Where to find the intensity (Updated Jan 23, 2004)
___________________________________________________________Where to find the intensity (Updated Dec 28, 2004)Member of UBAAG (Unban aftermath Association of Gamedev)
tok_junior
tok_junior
Slow? Well, ofcourse they are slower than your basic if(error), since it has to pass control to the exceptionhandler, but i think that''s a small price to pay for having a decent chance of recovering from a fatal error.
If the speed of a handler is a problem to you, there''s something seriously wrong with your code, since as you stated, it''s only called when something blows.
Sneftel
Sneftel
Exceptions are expensive to trigger, and cheap to not trigger. In other words, use all the try..catch blocks you want. But use exceptions to signal events that you don''t expect to happen very often, where if the event actually occurs, a drop in framerate is the least of your concerns. For instance, if you were making a software rasterizer, you wouldn''t want your fragment shader to throw an exception if the Z-buffer test failed.


"Sneftel is correct, if rather vulgar." --Flarelocke
Toni Petrina
Toni Petrina
Exceptions are not slow. Throwing is but that will rarely occur during game time. You expect that exceptions will not happen. If they do, you need to recover from that error. If exception is thrown during load time, you will tell user that level couldn''t be loaded (or engine initialized). In either case throw will cause penalty of no more tha percentage of second.

Exceptions are advanced error handling method. You won''t be using them that often. I use them in loading times where speed is not that neccessary and if they do happen while your game is active you will pause and deal with that error.
So... Muira Yoshimoto sliced off his head, walked 8 miles, and defeated a Mongolian horde... by beating them with his head?

Documentation? "We are writing games, we don't have to document anything".

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.