[Solved]SDL_GetError

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
XianForce
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 767
Joined: Wed Oct 29, 2008 8:36 pm

[Solved]SDL_GetError

Post 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 =)
Last edited by XianForce on Sun May 10, 2009 8:38 pm, edited 1 time in total.
User avatar
LuciDreamTheater
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 39
Joined: Tue Jan 20, 2009 2:18 am
Location: Southern CA
Contact:

Re: SDL_GetError

Post by LuciDreamTheater »

LazyFoo talks about it a little bit, although I haven't read the article.

http://lazyfoo.net/articles/article05/index.php
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: SDL_GetError

Post 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
}
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
XianForce
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 767
Joined: Wed Oct 29, 2008 8:36 pm

Re: SDL_GetError

Post by XianForce »

Thanks Guys, I got it from that article. I didn't think about outputting it to a file xD.
Post Reply