C doesn't support exceptions, but we can store error messages in structs. This document compares 3 different strategies of error reporting.
typedef enum {
FILE_NOT_FOUND_ERROR,
INVALID_FILE_FORMAT_ERROR,
...
Code: | |
Modular Character Controller (MIT) by Expresso Bits and Whimfoome. | |
Music: | |
Music by OceanKing from Pixabay. | |
Fonts: |
C doesn't support exceptions but GLib has its own error reporting system. It's kind of verbose but it works ok.
Let's pretend we were making a JSON parser library, here's how the error reporting would work. (This example was actually derived from json-glib).
First we create an enum to represent different error codes.
<script id="shader-vs" type="x-shader/x-vertex"> | |
attribute vec2 aPosition; | |
void main(void) { | |
gl_Position = vec4(aPosition, 0.0, 1.0); | |
} | |
</script> | |
<script id="shader-fs" type="x-shader/x-fragment"> | |
void main(void) { |