Jump to content
  • Advertisement

Archived

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

ugor

exceptions???

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

Let’s say that if a language like java didn’t have exceptions ie catching errors, what could be a possible solution so that error catching can be done? The reason why I am asking this is because I was thinking of making a method of reporting errors when I am programming in other languages that done have a feature like this, but I have no idea of how this might be done.

Share this post


Link to post
Share on other sites
Advertisement
There''s a laundry list of methods. Here''s a few that spring to mind.

* All functions return an error code, either as a return value or into an argument via pass-by-reference. The calling functions are responsible for checking that error code.
* A user-defined function is called on errors.
* A longjmp is done to an error handler.
* A global variable is set to the error code.
* The application is ended.

All of these have drawbacks. What language(s) do you need this for?


"Sneftel is correct, if rather vulgar." --Flarelocke

Share this post


Link to post
Share on other sites
I was thinking in general terms so that it could work on all languages. But if I was to implement it, I would do it in C.

Share this post


Link to post
Share on other sites
In C the best method IMHO is setjmp/longjmp. It''s a bad idea to specify a method for "all" languages, since most languages have a specific "best" way to do it.


"Sneftel is correct, if rather vulgar." --Flarelocke

Share this post


Link to post
Share on other sites
programming for exceptions and exception safety will change the design of your code.

in c++ the exceptional path of code is separated from the normal flow. try and catch actually isn''t what it''s about. it''s more to do with leaving things in a valid state if an exception occurs. read up on RAII (resource acquisition is initialisation).

relying upon return variables or having to check some global variable will affect the normal flow of code and result in exception safety being mixed up with everything else.

if you wrap c++ in boost.python you can translate between c++ and python exceptions. they are a great way to keep normal program flow clean.

read up on gotw.ca about everything to do with writing exception safe code.

eg.
Try and Catch Me
Difficulty: 3 / 10

Is exception safety all about writing try and catch in the right places? If not, then what? And what kinds of things should you consider when developing an exception safety policy for your software?

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!