Skip to content

Instantly share code, notes, and snippets.

@Linux-cpp-lisp
Created May 24, 2012 13:20
Show Gist options
  • Save Linux-cpp-lisp/2781511 to your computer and use it in GitHub Desktop.
Save Linux-cpp-lisp/2781511 to your computer and use it in GitHub Desktop.
A few small macros used to simplify error handling in C++ code that uses POSIX and UNIX system calls. Depends on an exception class UNIXError, which just happens to have an argument-less constructor that will get an error string based on the current value
#define ERR(__statment, __retVar) ((__retVar=(__statment))==-1 ? throw UNIXError() : (__retVar))
#define ERR_ERRVAL(__statment, __retVar, __errval) (((__retVar)=(__statment))==(__errval) ? throw UNIXError() : (__retVar))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment