Jump to content
  • Advertisement
Sign in to follow this  
Genjix

config file loading... exit on error, or warn?

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

in my game I check if the xml document exists and if it exists, I load it. If it doesn't I either warn or error and exit, depending on whats being loaded. This is getting quite tedious (always checking if file exists), so Im thinking, what are your thoughts on just putting an error and exit function in the Xml::Document constructor? Good or bad idea?

Share this post


Link to post
Share on other sites
Advertisement
In the constructor, throw an exception if the file is not found.

In the calling code, either catch the exception and warn, or 'error' by letting the exception fall through and terminate the app.

To avoid cloning the catch code several times, you can wrap it in its own function. Have some sane fall-back thing (an empty XMLDocument instance, whatever 'empty' means) to return in the failure case.

Share this post


Link to post
Share on other sites
I would do the same: wrap the checking code in a simple stand-alone function or two:

void ExitIfNotFound( filename );
void WarnIfNotFound( filename );

Share this post


Link to post
Share on other sites
the point is, every time I use it, I have to add the same error message over and over

if(!FileExist(src))
cerr << "error : " << src << " xml file non existant"
<< "... unable to continue\n" << Exit(-1);

whereas in some cases, I don't exit. But i'm thinking whether it is wise to exit all the time when there is no config file (2 lines in Xml::Document constructor) OR check the document nearly all the time and warn/exit.

I'd probably do something like leiavoia said (with bool in constructor).

Share this post


Link to post
Share on other sites
Provide multiple functions as leiavoia suggests. ExitIfNotFound is not meant as a replacement for FileExists, rather, as a supplement.

Personally, I'd suggest the use of exceptions to indicate missing files that are needed for continuation. That way, the client code can choose to either exit, or continue, depending on how it handles the exception.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!