Page 1 of 1

[Solved]SDL_GetError

Posted: Sun May 10, 2009 7:44 pm
by XianForce
If anyone uses this function, can you show me a small example of how to use it? I know it returns a NULL terminated string, but I'm not exactly sure how to go about using it.

My best guess would be something like:

Code: Select all

SDL_Surface* errorMessage=SDL_GetError();
and put that after pretty much everything, like initializing, loading and optimizing images, loading texts, etc.

But that seems inefficient to me, and it just seems like there's a better way to go about doing it.

So if anyone knows a better way (which I'm sure someone does) please let me in on it =)

Re: SDL_GetError

Posted: Sun May 10, 2009 7:53 pm
by LuciDreamTheater
LazyFoo talks about it a little bit, although I haven't read the article.

http://lazyfoo.net/articles/article05/index.php

Re: SDL_GetError

Posted: Sun May 10, 2009 8:30 pm
by MarauderIIC
The way other error functions work, like perror, is something like (this is probably how SDL_GetError works: )

Code: Select all

if (SDL_Init(...) == -1) {
    cout << "SDL Initialization error: " << SDL_GetError() << endl;
    exit(1);
}
Or more generally,

Code: Select all

if (someFunction() == errorCode) {
    cout << "Error calling someFunction in myFunction: " << getErrorFunction() << endl;
    handle error
}

Re: SDL_GetError

Posted: Sun May 10, 2009 8:37 pm
by XianForce
Thanks Guys, I got it from that article. I didn't think about outputting it to a file xD.