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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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__
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
60
#define CS_EXC_CONTEXT_SIZE 300
61
#define CS_EXC_MESSAGE_SIZE (PATH_MAX + 300)
62
#define CS_EXC_DETAILS_SIZE (CS_EXC_CONTEXT_SIZE + CS_EXC_MESSAGE_SIZE)
64
class CSException : public CSObject {
71
virtual ~CSException() { }
73
void setErrorCode(int e) { iErrorCode = e; }
74
const int getErrorCode() const { return iErrorCode; }
75
const char *getContext() const { return iContext; }
76
const char *getMessage() const { return iMessage; }
78
void setStackTrace(CSThread *self, const char *stack);
79
void setStackTrace(CSThread *self);
80
const char *getStackTrace();
82
void log(CSThread *self);
83
void log(CSThread *self, const char *message);
85
void initException(const char *func, const char *file, int line, int err, const char *message);
86
void initAssertion(const char *func, const char *file, int line, const char *message);
87
void getCoreError(u_int size, char *buffer, int err);
88
void initCoreError(const char *func, const char *file, int line, int err);
89
void initCoreError(const char *func, const char *file, int line, int err, const char *item);
90
void initOSError(const char *func, const char *file, int line, int err);
91
void initFileError(const char *func, const char *file, int line, const char *path, int err);
92
void initSignal(const char *func, const char *file, int line, int err);
93
void initEOFError(const char *func, const char *file, int line, const char *path);
95
static void RecordException(const char *func, const char *file, int line, int err, const char *message);
96
static void ClearException();
98
static void throwException(const char *func, const char *file, int line, int err, const char *message, const char *stack);
99
static void throwException(const char *func, const char *file, int line, int err, const char *message);
100
static void throwAssertion(const char *func, const char *file, int line, const char *message);
101
static void throwCoreError(const char *func, const char *file, int line, int err);
102
static void throwCoreError(const char *func, const char *file, int line, int err, const char *item);
103
static void throwOSError(const char *func, const char *file, int line, int err);
104
static void throwFileError(const char *func, const char *file, int line, const char *path, int err);
105
static void throwFileError(const char *func, const char *file, int line, CSString *path, int err);
106
static void throwSignal(const char *func, const char *file, int line, int err);
107
static void throwEOFError(const char *func, const char *file, int line, const char *path);
108
static void throwLastError(const char *func, const char *file, int line); /* Throw the last OS error: */
110
static void logOSError(const char *func, const char *file, int line, int err);
111
static void logOSError(CSThread *self, const char *func, const char *file, int line, int err);
112
static void logException(const char *func, const char *file, int line, int err, const char *message);
117
char iContext[CS_EXC_CONTEXT_SIZE]; /* func(file:line) */
118
char iMessage[CS_EXC_MESSAGE_SIZE]; /* The actual message of the error. */
119
CSStringBuffer iStackTrace;