Coverage Report

Created: 2025-07-01 06:08

/src/logging-log4cxx/src/main/cpp/exception.cpp
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 *
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
#define __STDC_WANT_LIB_EXT1__ 1
18
#include <log4cxx/logstring.h>
19
#include <log4cxx/helpers/exception.h>
20
#include <string.h>
21
#include <string>
22
#include <log4cxx/helpers/stringhelper.h>
23
#include <log4cxx/helpers/transcoder.h>
24
#include <log4cxx/helpers/pool.h>
25
#include <apr_errno.h>
26
27
using namespace LOG4CXX_NS;
28
using namespace LOG4CXX_NS::helpers;
29
30
Exception::Exception(const LogString& msg1)
31
0
{
32
0
  LOG4CXX_ENCODE_CHAR(m, msg1);
33
0
  size_t len = m.size();
34
35
0
  if (len > MSG_SIZE)
36
0
  {
37
0
    len = MSG_SIZE;
38
0
  }
39
40
#if defined(__STDC_LIB_EXT1__) || defined(__STDC_SECURE_LIB__)
41
  memcpy_s(msg, sizeof msg, m.data(), len);
42
#else
43
0
  memcpy(msg, m.data(), len);
44
0
#endif
45
0
  msg[len] = 0;
46
0
}
47
48
Exception::Exception(const char* m)
49
0
{
50
#if defined(__STDC_LIB_EXT1__) || defined(__STDC_SECURE_LIB__)
51
  strncpy_s(msg, sizeof msg, m, MSG_SIZE);
52
#else
53
0
  strncpy(msg, m, MSG_SIZE);
54
0
#endif
55
0
  msg[MSG_SIZE] = 0;
56
0
}
57
58
59
0
Exception::Exception(const Exception& src) : std::exception()
60
0
{
61
#if defined(__STDC_LIB_EXT1__) || defined(__STDC_SECURE_LIB__)
62
  strcpy_s(msg, sizeof msg, src.msg);
63
#else
64
0
  strncpy(msg, src.msg, MSG_SIZE);
65
0
  msg[MSG_SIZE] = 0;
66
0
#endif
67
0
}
68
69
Exception& Exception::operator=(const Exception& src)
70
0
{
71
#if defined(__STDC_LIB_EXT1__) || defined(__STDC_SECURE_LIB__)
72
  strcpy_s(msg, sizeof msg, src.msg);
73
#else
74
0
  strncpy(msg, src.msg, MSG_SIZE);
75
0
  msg[MSG_SIZE] = 0;
76
0
#endif
77
0
  return *this;
78
0
}
79
80
const char* Exception::what() const throw()
81
0
{
82
0
  return msg;
83
0
}
84
85
RuntimeException::RuntimeException(log4cxx_status_t stat)
86
0
  : Exception(formatMessage(stat))
87
0
{
88
0
}
89
90
RuntimeException::RuntimeException(const LogString& msg1)
91
0
  : Exception(msg1)
92
0
{
93
0
}
94
95
RuntimeException::RuntimeException(const RuntimeException& src)
96
0
  : Exception(src)
97
0
{
98
0
}
99
100
RuntimeException& RuntimeException::operator=(const RuntimeException& src)
101
0
{
102
0
  Exception::operator=(src);
103
0
  return *this;
104
0
}
105
106
LogString RuntimeException::formatMessage(log4cxx_status_t stat)
107
0
{
108
0
  LogString s(LOG4CXX_STR("RuntimeException: return code = "));
109
0
  Pool p;
110
0
  StringHelper::toString(stat, p, s);
111
0
  return s;
112
0
}
113
114
NullPointerException::NullPointerException(const LogString& msg1)
115
0
  : RuntimeException(msg1)
116
0
{
117
0
}
118
119
NullPointerException::NullPointerException(const NullPointerException& src)
120
0
  : RuntimeException(src)
121
0
{
122
0
}
123
124
NullPointerException& NullPointerException::operator=(const NullPointerException& src)
125
0
{
126
0
  RuntimeException::operator=(src);
127
0
  return *this;
128
0
}
129
130
IllegalArgumentException::IllegalArgumentException(const LogString& msg1)
131
0
  : RuntimeException(msg1)
132
0
{
133
0
}
134
135
IllegalArgumentException::IllegalArgumentException(const IllegalArgumentException& src)
136
0
  : RuntimeException(src)
137
0
{
138
0
}
139
140
IllegalArgumentException& IllegalArgumentException::operator=(const IllegalArgumentException& src)
141
0
{
142
0
  RuntimeException::operator=(src);
143
0
  return *this;
144
0
}
145
146
IOException::IOException()
147
0
  : Exception(LOG4CXX_STR("IO exception"))
148
0
{
149
0
}
150
151
IOException::IOException(log4cxx_status_t stat)
152
0
  : Exception(formatMessage(stat))
153
0
{
154
0
}
155
156
IOException::IOException(const LogString& type, log4cxx_status_t stat)
157
0
  : Exception(makeMessage(type, stat))
158
0
{
159
0
}
160
161
162
IOException::IOException(const LogString& msg1)
163
0
  : Exception(msg1)
164
0
{
165
0
}
166
167
IOException::IOException(const IOException& src)
168
0
  : Exception(src)
169
0
{
170
0
}
171
172
IOException& IOException::operator=(const IOException& src)
173
0
{
174
0
  Exception::operator=(src);
175
0
  return *this;
176
0
}
177
178
LogString IOException::formatMessage(log4cxx_status_t stat)
179
0
{
180
0
  return makeMessage(LOG4CXX_STR("IO Exception"), stat);
181
0
}
182
183
LogString Exception::makeMessage(const LogString& type, log4cxx_status_t stat)
184
0
{
185
0
  LogString s = type;
186
0
  char err_buff[1024] = {0};
187
0
  apr_strerror(stat, err_buff, sizeof(err_buff));
188
0
  if (0 == err_buff[0] || 0 == strncmp(err_buff, "APR does not understand", 23))
189
0
  {
190
0
    s.append(LOG4CXX_STR(": error code "));
191
0
    Pool p;
192
0
    StringHelper::toString(stat, p, s);
193
0
  }
194
0
  else
195
0
  {
196
0
    s.append(LOG4CXX_STR(" - "));
197
0
    std::string sMsg = err_buff;
198
0
    LOG4CXX_DECODE_CHAR(lsMsg, sMsg);
199
0
    s.append(lsMsg);
200
0
  }
201
0
  return s;
202
0
}
203
204
205
MissingResourceException::MissingResourceException(const LogString& key)
206
0
  : Exception(formatMessage(key))
207
0
{
208
0
}
209
210
211
MissingResourceException::MissingResourceException(const MissingResourceException& src)
212
0
  : Exception(src)
213
0
{
214
0
}
215
216
MissingResourceException& MissingResourceException::operator=(const MissingResourceException& src)
217
0
{
218
0
  Exception::operator=(src);
219
0
  return *this;
220
0
}
221
222
LogString MissingResourceException::formatMessage(const LogString& key)
223
0
{
224
0
  LogString s(LOG4CXX_STR("MissingResourceException: resource key = \""));
225
0
  s.append(key);
226
0
  s.append(LOG4CXX_STR("\"."));
227
0
  return s;
228
0
}
229
230
PoolException::PoolException(log4cxx_status_t stat)
231
0
  : Exception(formatMessage(stat))
232
0
{
233
0
}
234
235
PoolException::PoolException(const PoolException& src)
236
0
  : Exception(src)
237
0
{
238
0
}
239
240
PoolException& PoolException::operator=(const PoolException& src)
241
0
{
242
0
  Exception::operator=(src);
243
0
  return *this;
244
0
}
245
246
LogString PoolException::formatMessage(log4cxx_status_t stat)
247
0
{
248
0
  return makeMessage(LOG4CXX_STR("Pool exception"), stat);
249
0
}
250
251
252
TranscoderException::TranscoderException(log4cxx_status_t stat)
253
0
  : Exception(formatMessage(stat))
254
0
{
255
0
}
256
257
TranscoderException::TranscoderException(const TranscoderException& src)
258
0
  : Exception(src)
259
0
{
260
0
}
261
262
TranscoderException& TranscoderException::operator=(const TranscoderException& src)
263
0
{
264
0
  Exception::operator=(src);
265
0
  return *this;
266
0
}
267
268
LogString TranscoderException::formatMessage(log4cxx_status_t)
269
0
{
270
0
  return LOG4CXX_STR("Transcoder exception");
271
0
}
272
273
274
0
InterruptedException::InterruptedException() : Exception(LOG4CXX_STR("Thread was interrupted"))
275
0
{
276
0
}
277
278
InterruptedException::InterruptedException(log4cxx_status_t stat)
279
0
  : Exception(formatMessage(stat))
280
0
{
281
0
}
282
283
InterruptedException::InterruptedException(const InterruptedException& src)
284
0
  : Exception(src)
285
0
{
286
0
}
287
288
InterruptedException& InterruptedException::operator=(const InterruptedException& src)
289
0
{
290
0
  Exception::operator=(src);
291
0
  return *this;
292
0
}
293
294
LogString InterruptedException::formatMessage(log4cxx_status_t stat)
295
0
{
296
0
  LogString s(LOG4CXX_STR("InterruptedException: stat = "));
297
0
  Pool p;
298
0
  StringHelper::toString(stat, p, s);
299
0
  return s;
300
0
}
301
302
ThreadException::ThreadException(log4cxx_status_t stat)
303
0
  : Exception(formatMessage(stat))
304
0
{
305
0
}
306
307
ThreadException::ThreadException(const LogString& msg)
308
0
  : Exception(msg)
309
0
{
310
0
}
311
312
ThreadException::ThreadException(const ThreadException& src)
313
0
  : Exception(src)
314
0
{
315
0
}
316
317
ThreadException& ThreadException::operator=(const ThreadException& src)
318
0
{
319
0
  Exception::operator=(src);
320
0
  return *this;
321
0
}
322
323
LogString ThreadException::formatMessage(log4cxx_status_t stat)
324
0
{
325
0
  return makeMessage(LOG4CXX_STR("Thread exception"), stat);
326
0
}
327
328
IllegalMonitorStateException::IllegalMonitorStateException(const LogString& msg1)
329
0
  : Exception(msg1)
330
0
{
331
0
}
332
333
IllegalMonitorStateException::IllegalMonitorStateException(const IllegalMonitorStateException& src)
334
0
  : Exception(src)
335
0
{
336
0
}
337
338
IllegalMonitorStateException& IllegalMonitorStateException::operator=(const IllegalMonitorStateException& src)
339
0
{
340
0
  Exception::operator=(src);
341
0
  return *this;
342
0
}
343
344
InstantiationException::InstantiationException(const LogString& msg1)
345
0
  : Exception(msg1)
346
0
{
347
0
}
348
349
InstantiationException::InstantiationException(const InstantiationException& src)
350
0
  : Exception(src)
351
0
{
352
0
}
353
354
InstantiationException& InstantiationException::operator=(const InstantiationException& src)
355
0
{
356
0
  Exception::operator=(src);
357
0
  return *this;
358
0
}
359
360
ClassNotFoundException::ClassNotFoundException(const LogString& className)
361
0
  : Exception(formatMessage(className))
362
0
{
363
0
}
364
365
ClassNotFoundException::ClassNotFoundException(const ClassNotFoundException& src)
366
0
  : Exception(src)
367
0
{
368
0
}
369
370
371
ClassNotFoundException& ClassNotFoundException::operator=(const ClassNotFoundException& src)
372
0
{
373
0
  Exception::operator=(src);
374
0
  return *this;
375
0
}
376
377
LogString ClassNotFoundException::formatMessage(const LogString& className)
378
0
{
379
0
  LogString s(LOG4CXX_STR("Class not found: "));
380
0
  s.append(className);
381
0
  return s;
382
0
}
383
384
385
NoSuchElementException::NoSuchElementException()
386
0
  : Exception(LOG4CXX_STR("No such element"))
387
0
{
388
0
}
389
390
NoSuchElementException::NoSuchElementException(const NoSuchElementException& src)
391
0
  : Exception(src)
392
0
{
393
0
}
394
395
NoSuchElementException& NoSuchElementException::operator=(const NoSuchElementException& src)
396
0
{
397
0
  Exception::operator=(src);
398
0
  return *this;
399
0
}
400
401
402
IllegalStateException::IllegalStateException()
403
0
  : Exception(LOG4CXX_STR("Illegal state"))
404
0
{
405
0
}
406
407
IllegalStateException::IllegalStateException(const IllegalStateException& src)
408
0
  : Exception(src)
409
0
{
410
0
}
411
412
IllegalStateException& IllegalStateException::operator=(const IllegalStateException& src)
413
0
{
414
0
  Exception::operator=(src);
415
0
  return *this;
416
0
}
417
418
0
SocketException::SocketException(const LogString& msg) : IOException(msg)
419
0
{
420
0
}
421
422
0
SocketException::SocketException(log4cxx_status_t status) : IOException(status)
423
0
{
424
0
}
425
426
SocketException::SocketException(const SocketException& src)
427
0
  : IOException(src)
428
0
{
429
0
}
430
431
SocketException& SocketException::operator=(const SocketException& src)
432
0
{
433
0
  IOException::operator=(src);
434
0
  return *this;
435
0
}
436
437
0
ConnectException::ConnectException(log4cxx_status_t status) : SocketException(status)
438
0
{
439
0
}
440
441
ConnectException::ConnectException(const ConnectException& src)
442
0
  : SocketException(src)
443
0
{
444
0
}
445
446
ConnectException& ConnectException::operator=(const ConnectException& src)
447
0
{
448
0
  SocketException::operator=(src);
449
0
  return *this;
450
0
}
451
452
0
ClosedChannelException::ClosedChannelException() : SocketException(LOG4CXX_STR("Attempt to write to closed socket"))
453
0
{
454
0
}
455
456
ClosedChannelException::ClosedChannelException(const ClosedChannelException& src)
457
0
  : SocketException(src)
458
0
{
459
0
}
460
461
ClosedChannelException& ClosedChannelException::operator=(const ClosedChannelException& src)
462
0
{
463
0
  SocketException::operator=(src);
464
0
  return *this;
465
0
}
466
467
0
BindException::BindException(log4cxx_status_t status) : SocketException(status)
468
0
{
469
0
}
470
471
BindException::BindException(const BindException& src)
472
0
  : SocketException(src)
473
0
{
474
0
}
475
476
BindException& BindException::operator=(const BindException& src)
477
0
{
478
0
  SocketException::operator=(src);
479
0
  return *this;
480
0
}
481
482
0
InterruptedIOException::InterruptedIOException(const LogString& msg) : IOException(msg)
483
0
{
484
0
}
485
486
InterruptedIOException::InterruptedIOException(const InterruptedIOException& src)
487
0
  : IOException(src)
488
0
{
489
0
}
490
491
InterruptedIOException& InterruptedIOException::operator=(const InterruptedIOException& src)
492
0
{
493
0
  IOException::operator=(src);
494
0
  return *this;
495
0
}
496
497
SocketTimeoutException::SocketTimeoutException()
498
0
  : InterruptedIOException(LOG4CXX_STR("SocketTimeoutException"))
499
0
{
500
0
}
501
502
SocketTimeoutException::SocketTimeoutException(const SocketTimeoutException& src)
503
0
  : InterruptedIOException(src)
504
0
{
505
0
}
506
507
SocketTimeoutException& SocketTimeoutException::operator=(const SocketTimeoutException& src)
508
0
{
509
0
  InterruptedIOException::operator=(src);
510
0
  return *this;
511
0
}