JWS C Library
C language utility library
error.h
Go to the documentation of this file.
00001 /*
00002  * This work is licensed under a Creative Commons 
00003  * Attribution-Noncommercial-Share Alike 3.0 United States License.
00004  * 
00005  *    http://creativecommons.org/licenses/by-nc-sa/3.0/us/
00006  * 
00007  * You are free:
00008  * 
00009  *    to Share - to copy, distribute, display, and perform the work
00010  *    to Remix - to make derivative works
00011  * 
00012  * Under the following conditions:
00013  * 
00014  *    Attribution. You must attribute the work in the manner specified by the
00015  *    author or licensor (but not in any way that suggests that they endorse you
00016  *    or your use of the work).
00017  * 
00018  *    Noncommercial. You may not use this work for commercial purposes.
00019  * 
00020  *    Share Alike. If you alter, transform, or build upon this work, you may
00021  *    distribute the resulting work only under the same or similar license to
00022  *    this one.
00023  * 
00024  * For any reuse or distribution, you must make clear to others the license
00025  * terms of this work. The best way to do this is by including this header.
00026  * 
00027  * Any of the above conditions can be waived if you get permission from the
00028  * copyright holder.
00029  * 
00030  * Apart from the remix rights granted under this license, nothing in this
00031  * license impairs or restricts the author's moral rights.
00032  */
00033 
00034 
00046 #ifndef ERROR_H
00047 #define ERROR_H
00048 
00049 
00050 #include <jwsc/config.h>
00051 
00052 #include <stdlib.h>
00053 #include <inttypes.h>
00054 
00055 
00056 #ifdef __cplusplus
00057 namespace jwsc {
00058 extern "C" {
00059 #endif
00060 
00061 
00063 typedef enum
00064 {
00065     ERROR_NO_MEMORY,     
00066     ERROR_IO,            
00067     ERROR_INV_ARG,       
00068     ERROR_CALC,          
00069     ERROR_NOT_READY,     
00070     ERROR_SOCKET,        
00071     ERROR_CONNECT        
00072 }
00073 Error_type;
00074 
00075 
00077 typedef struct
00078 {
00080     Error_type type;
00081 
00083     char* msg;
00084 
00086     char* file;
00087 
00089     unsigned int line;
00090 
00092     int code;
00093 }
00094 Error;
00095 
00096 
00102 extern Error* error_no_memory;
00103 
00104 
00106 Error* create_error
00107 (
00108     Error_type   type, 
00109     const char*  file,
00110     unsigned int line,
00111     const char*  msg
00112 );
00113 
00114 
00116 void free_error(Error* e);
00117 
00118 
00120 void print_error(const char* prefix, const Error* e);
00121 
00122 
00124 void print_error_exit(const char* prefix, const Error* e);
00125 
00126 
00128 void print_error_msg(const char* prefix, const char* msg);
00129 
00130 
00132 void print_error_msg_exit(const char* prefix, const char* msg);
00133 
00134 
00139 void print_errno(const char* prefix);
00140 
00141 
00146 void print_errno_exit(const char* prefix);
00147 
00148 
00150 uint32_t get_num_unhandled_errors();
00151 
00152 
00162 #define  JWSC_EARG(msg)  create_error(ERROR_INV_ARG, __FILE__, __LINE__, msg)
00163 
00164 
00174 #define  JWSC_EIO(msg)  create_error(ERROR_IO, __FILE__, __LINE__, msg)
00175 
00176 
00186 #define  JWSC_ECALC(msg)  create_error(ERROR_CALC, __FILE__, __LINE__, msg)
00187 
00188 
00189 #ifdef __cplusplus
00190 }
00191 }
00192 #endif
00193 
00194 
00195 #endif