diff options
Diffstat (limited to 'src/errors.h')
-rw-r--r-- | src/errors.h | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/errors.h b/src/errors.h new file mode 100644 index 000000000..525cb0f09 --- /dev/null +++ b/src/errors.h @@ -0,0 +1,48 @@ +#ifndef INCLUDE_errors_h__ +#define INCLUDE_errors_h__ + +#include "git2/common.h" + +/* Deprecated - please use the more advanced functions below. */ +#define git__throw(error, ...) \ + (git_error_createf(__FILE__, __LINE__, error, __VA_ARGS__), error) + +#define git__rethrow(error, ...) \ + (git_error_createf(__FILE__, __LINE__, error, __VA_ARGS__), error) + +/* + * This implementation is loosely based on subversion's error + * handling. + */ + +git_error * git_error_createf(const char *file, unsigned int line, int code, + const char *msg, ...) GIT_FORMAT_PRINTF(4, 5); + +git_error * git_error__quick_wrap(const char *file, int line, + git_error_code error, const char *msg); + +/* + * Wrap an error with a message. All git_error values are assigned with + * child's fields. + */ +#define git_error_quick_wrap(error, message) \ + git_error__quick_wrap(__FILE__, __LINE__, error, message) + +/* + * Use this function to wrap functions like + * + * git_error * foo(void) + * { + * return git_error_trace(bar()); + * } + * + * Otherwise the call of foo() wouldn't be visible in the trace. + * + */ +#define git_error_trace(error) \ + git_error_quick_wrap(error, "traced error"); + +/* Throw an out-of-memory error */ +extern git_error * git_error_oom(void); + +#endif /* INCLUDE_errors_h__ */ |