00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #pragma once
00029 #ifndef __CSEXEPTION_H__
00030 #define __CSEXEPTION_H__
00031
00032 #include <errno.h>
00033 #include <limits.h>
00034 #include <stdarg.h>
00035
00036 #include "CSDefs.h"
00037 #include "CSString.h"
00038 #include "CSObject.h"
00039
00040 #define CS_ERR_ASSERTION -14000
00041 #define CS_ERR_EOF -14001
00042 #define CS_ERR_JUMP_OVERFLOW -14002
00043 #define CS_ERR_BAD_ADDRESS -14003
00044 #define CS_ERR_UNKNOWN_SERVICE -14004
00045 #define CS_ERR_UNKNOWN_HOST -14005
00046 #define CS_ERR_UNKNOWN_METHOD -14006
00047 #define CS_ERR_NO_LISTENER -14007
00048 #define CS_ERR_GENERIC_ERROR -14008
00049 #define CS_ERR_RELEASE_OVERFLOW -14009
00050 #define CS_ERR_IMPL_MISSING -14010
00051 #define CS_ERR_BAD_HEADER_MAGIC -14011
00052 #define CS_ERR_VERSION_TOO_NEW -14012
00053 #define CS_ERR_BAD_FILE_HEADER -14013
00054 #define CS_ERR_BAD_HTTP_HEADER -14014
00055 #define CS_ERR_INVALID_RECORD -14015
00056 #define CS_ERR_CHECKSUM_ERROR -14016
00057 #define CS_ERR_MISSING_HTTP_HEADER -14017
00058 #define CS_ERR_OPERATION_NOT_SUPPORTED -14018
00059 #define CS_ERR_BODY_INCOMPLETE -14019
00060 #define CS_ERR_RECEIVE_TIMEOUT -14020
00061
00062 #define CS_EXC_CONTEXT_SIZE 300
00063 #define CS_EXC_MESSAGE_SIZE (PATH_MAX + 300)
00064 #define CS_EXC_DETAILS_SIZE (CS_EXC_CONTEXT_SIZE + CS_EXC_MESSAGE_SIZE)
00065
00066 class CSException : public CSObject {
00067 public:
00068 CSException() {
00069 iErrorCode = 0;
00070 iContext[0] = 0;
00071 iMessage[0] = 0;
00072 }
00073 virtual ~CSException() { }
00074
00075 void setErrorCode(int e) { iErrorCode = e; }
00076 int getErrorCode() { return iErrorCode; }
00077 const char *getContext(){ return iContext; }
00078 const char *getMessage(){ return iMessage; }
00079
00080 void setStackTrace(CSThread *self, const char *stack);
00081 void setStackTrace(CSThread *self);
00082 const char *getStackTrace();
00083
00084 void log(CSThread *self);
00085 void log(CSThread *self, const char *message);
00086
00087 void initException_va(const char *func, const char *file, int line, int err, const char *fmt, va_list ap);
00088 void initException(CSException &exception);
00089 void initExceptionf(const char *func, const char *file, int line, int err, const char *fmt, ...);
00090 void initException(const char *func, const char *file, int line, int err, const char *message);
00091 void initAssertion(const char *func, const char *file, int line, const char *message);
00092 void getCoreError(uint32_t size, char *buffer, int err);
00093 void initCoreError(const char *func, const char *file, int line, int err);
00094 void initCoreError(const char *func, const char *file, int line, int err, const char *item);
00095 void initOSError(const char *func, const char *file, int line, int err);
00096 void initFileError(const char *func, const char *file, int line, const char *path, int err);
00097 void initSignal(const char *func, const char *file, int line, int err);
00098 void initEOFError(const char *func, const char *file, int line, const char *path);
00099
00100 static void RecordException(const char *func, const char *file, int line, int err, const char *message);
00101 static void ClearException();
00102
00103 static void throwException(const char *func, const char *file, int line, int err, const char *message, const char *stack);
00104 static void throwException(const char *func, const char *file, int line, int err, const char *message);
00105 static void throwExceptionf(const char *func, const char *file, int line, int err, const char *fmt, ...);
00106 static void throwAssertion(const char *func, const char *file, int line, const char *message);
00107 static void throwCoreError(const char *func, const char *file, int line, int err);
00108 static void throwCoreError(const char *func, const char *file, int line, int err, const char *item);
00109 static void throwOSError(const char *func, const char *file, int line, int err);
00110 static void throwFileError(const char *func, const char *file, int line, const char *path, int err);
00111 static void throwFileError(const char *func, const char *file, int line, CSString *path, int err);
00112 static void throwSignal(const char *func, const char *file, int line, int err);
00113 static void throwEOFError(const char *func, const char *file, int line, const char *path);
00114 static void throwLastError(const char *func, const char *file, int line);
00115
00116 static void logOSError(const char *func, const char *file, int line, int err);
00117 static void logOSError(CSThread *self, const char *func, const char *file, int line, int err);
00118 static void logException(const char *func, const char *file, int line, int err, const char *message);
00119
00120 private:
00121
00122 int iErrorCode;
00123 char iContext[CS_EXC_CONTEXT_SIZE];
00124 char iMessage[CS_EXC_MESSAGE_SIZE];
00125 CSStringBuffer iStackTrace;
00126 };
00127
00128 #endif