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.
29
#ifndef __CSEXEPTION_H__
30
#define __CSEXEPTION_H__
40
#define CS_ERR_ASSERTION -14000
41
#define CS_ERR_EOF -14001
42
#define CS_ERR_JUMP_OVERFLOW -14002
43
#define CS_ERR_BAD_ADDRESS -14003
44
#define CS_ERR_UNKNOWN_SERVICE -14004
45
#define CS_ERR_UNKNOWN_HOST -14005
46
#define CS_ERR_UNKNOWN_METHOD -14006
47
#define CS_ERR_NO_LISTENER -14007
48
#define CS_ERR_GENERIC_ERROR -14008
49
#define CS_ERR_RELEASE_OVERFLOW -14009
50
#define CS_ERR_IMPL_MISSING -14010
51
#define CS_ERR_BAD_HEADER_MAGIC -14011
52
#define CS_ERR_VERSION_TOO_NEW -14012
53
#define CS_ERR_BAD_FILE_HEADER -14013
54
#define CS_ERR_BAD_HTTP_HEADER -14014
55
#define CS_ERR_INVALID_RECORD -14015
56
#define CS_ERR_CHECKSUM_ERROR -14016
57
#define CS_ERR_MISSING_HTTP_HEADER -14017
58
#define CS_ERR_OPERATION_NOT_SUPPORTED -14018
59
#define CS_ERR_BODY_INCOMPLETE -14019
60
#define CS_ERR_RECEIVE_TIMEOUT -14020
62
#define CS_EXC_CONTEXT_SIZE 300
63
#define CS_EXC_MESSAGE_SIZE (PATH_MAX + 300)
64
#define CS_EXC_DETAILS_SIZE (CS_EXC_CONTEXT_SIZE + CS_EXC_MESSAGE_SIZE)
66
class CSException : public CSObject {
73
virtual ~CSException() { }
75
void setErrorCode(int e) { iErrorCode = e; }
76
int getErrorCode() { return iErrorCode; }
77
const char *getContext(){ return iContext; }
78
const char *getMessage(){ return iMessage; }
80
void setStackTrace(CSThread *self, const char *stack);
81
void setStackTrace(CSThread *self);
82
const char *getStackTrace();
84
void log(CSThread *self);
85
void log(CSThread *self, const char *message);
87
void initException_va(const char *func, const char *file, int line, int err, const char *fmt, va_list ap);
88
void initException(CSException &exception);
89
void initExceptionf(const char *func, const char *file, int line, int err, const char *fmt, ...);
90
void initException(const char *func, const char *file, int line, int err, const char *message);
91
void initAssertion(const char *func, const char *file, int line, const char *message);
92
void getCoreError(uint32_t size, char *buffer, int err);
93
void initCoreError(const char *func, const char *file, int line, int err);
94
void initCoreError(const char *func, const char *file, int line, int err, const char *item);
95
void initOSError(const char *func, const char *file, int line, int err);
96
void initFileError(const char *func, const char *file, int line, const char *path, int err);
97
void initSignal(const char *func, const char *file, int line, int err);
98
void initEOFError(const char *func, const char *file, int line, const char *path);
100
static void RecordException(const char *func, const char *file, int line, int err, const char *message);
101
static void ClearException();
103
static void throwException(const char *func, const char *file, int line, int err, const char *message, const char *stack);
104
static void throwException(const char *func, const char *file, int line, int err, const char *message);
105
static void throwExceptionf(const char *func, const char *file, int line, int err, const char *fmt, ...);
106
static void throwAssertion(const char *func, const char *file, int line, const char *message);
107
static void throwCoreError(const char *func, const char *file, int line, int err);
108
static void throwCoreError(const char *func, const char *file, int line, int err, const char *item);
109
static void throwOSError(const char *func, const char *file, int line, int err);
110
static void throwFileError(const char *func, const char *file, int line, const char *path, int err);
111
static void throwFileError(const char *func, const char *file, int line, CSString *path, int err);
112
static void throwSignal(const char *func, const char *file, int line, int err);
113
static void throwEOFError(const char *func, const char *file, int line, const char *path);
114
static void throwLastError(const char *func, const char *file, int line); /* Throw the last OS error: */
116
static void logOSError(const char *func, const char *file, int line, int err);
117
static void logOSError(CSThread *self, const char *func, const char *file, int line, int err);
118
static void logException(const char *func, const char *file, int line, int err, const char *message);
123
char iContext[CS_EXC_CONTEXT_SIZE]; /* func(file:line) */
124
char iMessage[CS_EXC_MESSAGE_SIZE]; /* The actual message of the error. */
125
CSStringBuffer iStackTrace;