source: Sophya/trunk/SophyaExt/JThreadsC++/JTCSrc/JTC/Exception.h@ 1016

Last change on this file since 1016 was 1016, checked in by ansari, 25 years ago

Creation du module JThreadsC++, importation du code des classes
de Thread a la Java de Object Oriented Concepts Inc - Reza 19/5/2000

File size: 3.5 KB
Line 
1// **********************************************************************
2//
3// Copyright (c) 2000
4// Object Oriented Concepts, Inc.
5// Billerica, MA, USA
6//
7// All Rights Reserved
8//
9// **********************************************************************
10
11#ifndef JTC_EXCEPTION_H
12#define JTC_EXCEPTION_H
13
14//
15// Exception hierarchy for JTC.
16//
17// JTCThreadDeath
18//
19// JTCException
20// |
21// +-- JTCInterruptedException
22// |
23// +-- JTCIllegalThreadStateException
24// |
25// +-- JTCIllegalArgumentException
26// |
27// +-- JTCSystemCallException
28// |
29// +-- JTCOutOfMemoryError
30// |
31// +-- JTCIllegalMonitorStateException
32// |
33// +-- JTCUnknownThreadException
34//
35
36#include <string.h>
37
38class JTCThreadDeath
39{
40};
41
42class JTCException
43{
44 char* note_;
45 int error_;
46
47public:
48
49 JTCException(const char* note = "", long error = 0)
50 : error_(error)
51 {
52 note_ = new char[strlen(note) + 1];
53 strcpy(note_, note);
54 }
55
56 JTCException(const JTCException& e)
57 : error_(e.error_)
58 {
59 note_ = new char[strlen(e.note_) +1];
60 strcpy(note_, e.note_);
61 }
62
63 JTCException& operator=(const JTCException& e)
64 {
65 if(this != &e)
66 {
67 error_ = e.error_;
68 note_ = new char[strlen(e.note_) +1];
69 strcpy(note_, e.note_);
70 }
71 return *this;
72 }
73
74 virtual ~JTCException()
75 {
76 delete[] note_;
77 }
78
79 long getError() const
80 {
81 return error_;
82 }
83
84 virtual const char* getType() const
85 {
86 return "JTCException";
87 }
88
89 const char* getMessage() const
90 {
91 return note_;
92 }
93};
94
95inline JTC_STD(ostream)&
96operator<<(JTC_STD(ostream)& os, const JTCException& e)
97{
98 os << e.getType() << ": " << e.getMessage();
99 return os;
100}
101
102
103class JTCInterruptedException : public JTCException
104{
105public:
106
107 JTCInterruptedException() {}
108 JTCInterruptedException(const char* note)
109 : JTCException(note) { }
110
111 virtual const char* getType() const
112 {
113 return "JTCInterruptedException";
114 }
115};
116
117class JTCIllegalThreadStateException : public JTCException
118{
119public:
120
121 JTCIllegalThreadStateException() {}
122 JTCIllegalThreadStateException(const char* note)
123 : JTCException(note) { }
124
125 virtual const char* getType() const
126 {
127 return "JTCIllegalThreadStateException";
128 }
129};
130
131class JTCIllegalMonitorStateException : public JTCException
132{
133public:
134
135 JTCIllegalMonitorStateException() { }
136 JTCIllegalMonitorStateException(const char* note)
137 : JTCException(note) { }
138
139 virtual const char* getType() const
140 {
141 return "JTCIllegalMonitorStateException";
142 }
143};
144
145class JTCIllegalArgumentException : public JTCException
146{
147public:
148
149 JTCIllegalArgumentException() { }
150 JTCIllegalArgumentException(const char* note)
151 : JTCException(note) { }
152
153 virtual const char* getType() const
154 {
155 return "JTCIllegalArgumentException";
156 }
157};
158
159class JTCSystemCallException : public JTCException
160{
161public:
162
163 JTCSystemCallException(const char* note, long error)
164 : JTCException(note, error) { }
165
166 virtual const char* getType() const
167 {
168 return "JTCSystemCallException";
169 }
170};
171
172class JTCOutOfMemoryError : public JTCException
173{
174public:
175
176 JTCOutOfMemoryError() { }
177 JTCOutOfMemoryError(const char* note)
178 : JTCException(note) { }
179
180 virtual const char* getType() const
181 {
182 return "JTCOutOfMemoryError";
183 }
184};
185
186class JTCUnknownThreadException : public JTCException
187{
188public:
189
190 JTCUnknownThreadException() { }
191 JTCUnknownThreadException(const char* note)
192 : JTCException(note) { }
193
194 virtual const char* getType() const
195 {
196 return "JTCUnknownThreadException";
197 }
198};
199
200#endif
Note: See TracBrowser for help on using the repository browser.