BSON Error Encapsulation


#include <bson.h>

typedef struct
   uint32_t domain;
   uint32_t code;
   char     message[504];
} bson_error_t;


The bson_error_t structure is used to encapsulate information about an error. Think of it as the information stored in an exception without stack trace information. It includes information about the module and error code of the error along with a human printable message.

The error.domain field contains the logical domain within a library that created the error. This might be the JSON subsystem or bson_reader_t for example.

The error.code field contains the domain specific error code.

The error.message field contains a human printable error message.


Print Error Information

bson_reader_t *reader;
bson_error_t error;

reader = bson_reader_new_from_file ("dump.bson", &error);
if (!reader) {
   fprintf (stderr, "ERROR: %d.%d: %s\n",
            error.domain, error.code, error.message);