Should I handle every single possible error when using SDL?

If I account for every single possible errors when using SDL functions, the code needed to make a minimal window will look something like this:

#include <SDl2/SDL.h>
#include <stdbool.h>



int main(int argc, char *argv[]) {
    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
        // Error handling here
    }

    SDL_Window *window = SDL_CreateWindow("Test", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 500, 300, 0);
    if (window == NULL) {
        // Error handling here
    }
    
    SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
    if (renderer == NULL) {
        // Error handling here
    }
    
    SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); // This can also fail, so should we handle it just in case?
    bool active = true;
    SDL_Event event;
    Uint8 r, g, b, a;
    while (active) {
        while (SDL_PollEvent(&event) > 0) {
            switch (event.type) {
            case SDL_QUIT:
                active = false;
                break;
        }
    }
            if (SDL_RenderClear(renderer) < 0) {
                // More error handling
	if (SDL_RenderPresent(renderer) < 0) {
                // More error handling
            }
    }

// And also for these...
    SDL_DestroyRenderer(renderer);
    SDL_DestroyWindow(window);
    SDL_Quit();

    return 0;
}

I don’t want to do the tedious act of writing the error handling part over and over again. Should I handle every error that can happen just in case? Thanks.

I show an SDL message box if any of the commands fail before the while loop starts, just so a user could get in touch with me if anything has gone wrong and let me know which function failed.

Once the app is up and running in the while loop I don’t bother catching the errors, as if any fail the app is probably going to crash anyway. They can be useful while you’re debugging if an SDL function fails and you want to drill down why.

You don’t really need to check for errors for stuff like SDL_SetRenderDrawColor() or SDL_RenderClear(). For the actual setup, anything where you’re saving/loading, etc, yes, definitely check for errors. For setup errors, like @SeanOConnor said, you can just pop up a message box with SDL_ShowSimpleMessageBox() or whatever to let the user know your app can’t go on and then bail out.

Also, get used to the fact that in C a lot of your code will be error checking. :man_shrugging: