1
/* Copyright (C) 2008 PrimeBase Technologies GmbH, Germany
3
* PrimeBase Media Stream for MySQL
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
* Original author: Paul McCullagh (H&G2JCtL)
20
* Continued development: Barry Leslie
24
* The root of all exceptions.
28
#ifndef __CSEXEPTION_H__
29
#define __CSEXEPTION_H__
39
#define CS_ERR_ASSERTION -14000
40
#define CS_ERR_EOF -14001
41
#define CS_ERR_JUMP_OVERFLOW -14002
42
#define CS_ERR_BAD_ADDRESS -14003
43
#define CS_ERR_UNKNOWN_SERVICE -14004
44
#define CS_ERR_UNKNOWN_HOST -14005
45
#define CS_ERR_UNKNOWN_METHOD -14006
46
#define CS_ERR_NO_LISTENER -14007
47
#define CS_ERR_GENERIC_ERROR -14008
48
#define CS_ERR_RELEASE_OVERFLOW -14009
49
#define CS_ERR_IMPL_MISSING -14010
50
#define CS_ERR_BAD_HEADER_MAGIC -14011
51
#define CS_ERR_VERSION_TOO_NEW -14012
52
#define CS_ERR_BAD_FILE_HEADER -14013
53
#define CS_ERR_BAD_HTTP_HEADER -14014
54
#define CS_ERR_INVALID_RECORD -14015
55
#define CS_ERR_CHECKSUM_ERROR -14016
56
#define CS_ERR_MISSING_HTTP_HEADER -14017
57
#define CS_ERR_OPERATION_NOT_SUPPORTED -14018
58
#define CS_ERR_BODY_INCOMPLETE -14019
59
#define CS_ERR_RECEIVE_TIMEOUT -14020
61
#define CS_EXC_CONTEXT_SIZE 300
62
#define CS_EXC_MESSAGE_SIZE (PATH_MAX + 300)
63
#define CS_EXC_DETAILS_SIZE (CS_EXC_CONTEXT_SIZE + CS_EXC_MESSAGE_SIZE)
65
class CSException : public CSObject {
72
virtual ~CSException() { }
74
void setErrorCode(int e) { iErrorCode = e; }
75
int getErrorCode() { return iErrorCode; }
76
const char *getContext(){ return iContext; }
77
const char *getMessage(){ return iMessage; }
79
void setStackTrace(CSThread *self, const char *stack);
80
void setStackTrace(CSThread *self);
81
const char *getStackTrace();
83
void log(CSThread *self);
84
void log(CSThread *self, const char *message);
86
void initException_va(const char *func, const char *file, int line, int err, const char *fmt, va_list ap);
87
void initException(CSException &exception);
88
void initExceptionf(const char *func, const char *file, int line, int err, const char *fmt, ...);
89
void initException(const char *func, const char *file, int line, int err, const char *message);
90
void initAssertion(const char *func, const char *file, int line, const char *message);
91
void getCoreError(uint32_t size, char *buffer, int err);
92
void initCoreError(const char *func, const char *file, int line, int err);
93
void initCoreError(const char *func, const char *file, int line, int err, const char *item);
94
void initOSError(const char *func, const char *file, int line, int err);
95
void initFileError(const char *func, const char *file, int line, const char *path, int err);
96
void initSignal(const char *func, const char *file, int line, int err);
97
void initEOFError(const char *func, const char *file, int line, const char *path);
99
static void RecordException(const char *func, const char *file, int line, int err, const char *message);
100
static void ClearException();
102
static void throwException(const char *func, const char *file, int line, int err, const char *message, const char *stack);
103
static void throwException(const char *func, const char *file, int line, int err, const char *message);
104
static void throwExceptionf(const char *func, const char *file, int line, int err, const char *fmt, ...);
105
static void throwAssertion(const char *func, const char *file, int line, const char *message);
106
static void throwCoreError(const char *func, const char *file, int line, int err);
107
static void throwCoreError(const char *func, const char *file, int line, int err, const char *item);
108
static void throwOSError(const char *func, const char *file, int line, int err);
109
static void throwFileError(const char *func, const char *file, int line, const char *path, int err);
110
static void throwFileError(const char *func, const char *file, int line, CSString *path, int err);
111
static void throwSignal(const char *func, const char *file, int line, int err);
112
static void throwEOFError(const char *func, const char *file, int line, const char *path);
113
static void throwLastError(const char *func, const char *file, int line); /* Throw the last OS error: */
115
static void logOSError(const char *func, const char *file, int line, int err);
116
static void logOSError(CSThread *self, const char *func, const char *file, int line, int err);
117
static void logException(const char *func, const char *file, int line, int err, const char *message);
122
char iContext[CS_EXC_CONTEXT_SIZE]; /* func(file:line) */
123
char iMessage[CS_EXC_MESSAGE_SIZE]; /* The actual message of the error. */
124
CSStringBuffer iStackTrace;