Coverage Report

Created: 2026-06-15 06:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/logging-log4cxx/src/main/cpp/exception.cpp
Line
Count
Source
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 <apr_errno.h>
25
#include <apr_thread_proc.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
  msg = m;
34
0
}
35
36
Exception::Exception(const char* m)
37
0
{
38
0
  msg = (m ? std::string(m) : std::string());
39
0
}
40
41
42
0
Exception::Exception(const Exception& src) : std::exception()
43
0
{
44
0
  msg = src.msg;
45
0
}
46
47
Exception& Exception::operator=(const Exception& src)
48
0
{
49
0
  msg = src.msg;
50
0
  return *this;
51
0
}
52
53
const char* Exception::what() const throw()
54
0
{
55
0
  return msg.c_str();
56
0
}
57
58
RuntimeException::RuntimeException(log4cxx_status_t stat)
59
0
  : Exception(formatMessage(stat))
60
0
{
61
0
}
62
63
RuntimeException::RuntimeException(const LogString& msg1)
64
0
  : Exception(msg1)
65
0
{
66
0
}
67
68
RuntimeException::RuntimeException(const RuntimeException& src)
69
0
  : Exception(src)
70
0
{
71
0
}
72
73
RuntimeException& RuntimeException::operator=(const RuntimeException& src)
74
0
{
75
0
  Exception::operator=(src);
76
0
  return *this;
77
0
}
78
79
LogString RuntimeException::formatMessage(log4cxx_status_t stat)
80
0
{
81
0
  LogString s(LOG4CXX_STR("RuntimeException: return code = "));
82
0
  StringHelper::toString(stat, s);
83
0
  return s;
84
0
}
85
86
NullPointerException::NullPointerException(const LogString& msg1)
87
0
  : RuntimeException(msg1 + LOG4CXX_STR(" may not be null"))
88
0
{
89
0
}
90
91
NullPointerException::NullPointerException(const NullPointerException& src)
92
0
  : RuntimeException(src)
93
0
{
94
0
}
95
96
NullPointerException& NullPointerException::operator=(const NullPointerException& src)
97
0
{
98
0
  RuntimeException::operator=(src);
99
0
  return *this;
100
0
}
101
102
IllegalArgumentException::IllegalArgumentException(const LogString& msg1)
103
0
  : RuntimeException(msg1)
104
0
{
105
0
}
106
107
IllegalArgumentException::IllegalArgumentException(const IllegalArgumentException& src)
108
0
  : RuntimeException(src)
109
0
{
110
0
}
111
112
IllegalArgumentException& IllegalArgumentException::operator=(const IllegalArgumentException& src)
113
0
{
114
0
  RuntimeException::operator=(src);
115
0
  return *this;
116
0
}
117
118
IOException::IOException()
119
0
  : Exception(LOG4CXX_STR("IO exception"))
120
0
{
121
0
}
122
123
IOException::IOException(log4cxx_status_t stat)
124
0
  : Exception(formatMessage(stat))
125
0
{
126
0
}
127
128
IOException::IOException(const LogString& type, log4cxx_status_t stat)
129
0
  : Exception(makeMessage(type, stat))
130
0
{
131
0
}
132
133
#if !LOG4CXX_LOGCHAR_IS_UTF8
134
IOException::IOException(const char* type, log4cxx_status_t stat)
135
  : Exception(makeMessage(type, stat).c_str())
136
{
137
}
138
#endif
139
140
IOException::IOException(const char* msg1)
141
0
  : Exception(msg1)
142
0
{
143
0
}
144
145
IOException::IOException(const LogString& msg1)
146
0
  : Exception(msg1)
147
0
{
148
0
}
149
150
IOException::IOException(const IOException& src)
151
0
  : Exception(src)
152
0
{
153
0
}
154
155
IOException& IOException::operator=(const IOException& src)
156
0
{
157
0
  Exception::operator=(src);
158
0
  return *this;
159
0
}
160
161
LogString IOException::formatMessage(log4cxx_status_t stat)
162
0
{
163
0
  return makeMessage(LOG4CXX_STR("IO Exception"), stat);
164
0
}
165
166
SubProcessFailure::SubProcessFailure(const LogString& processName, int exitCode, int exitWhy)
167
0
  : Exception(makeMessage(processName, exitCode, exitWhy))
168
0
{
169
0
}
170
171
#if !LOG4CXX_LOGCHAR_IS_UTF8
172
SubProcessFailure::SubProcessFailure(const char* processName, int exitCode, int exitWhy)
173
  : Exception(makeMessage(Transcoder::decode(processName), exitCode, exitWhy))
174
{
175
}
176
#endif
177
178
SubProcessFailure::SubProcessFailure(const SubProcessFailure& src)
179
0
  : Exception(src)
180
0
{
181
0
}
182
183
SubProcessFailure& SubProcessFailure::operator=(const SubProcessFailure& src)
184
0
{
185
0
  Exception::operator=(src);
186
0
  return *this;
187
0
}
188
189
LogString SubProcessFailure::makeMessage(const LogString& processName, int exitCode, int exitWhy)
190
0
{
191
0
  LogString msg = processName;
192
0
  msg += LOG4CXX_STR(" exit code: ");
193
0
  LogString codeStr;
194
0
  StringHelper::toString(exitCode, codeStr);
195
0
  msg += codeStr;
196
0
  if (APR_PROC_SIGNAL == exitWhy || APR_PROC_SIGNAL_CORE == exitWhy)
197
0
  {
198
0
    msg += LOG4CXX_STR("; exited due to a signal");
199
0
  }
200
0
  return msg;
201
0
}
202
203
LogString Exception::makeMessage(const LogString& type, log4cxx_status_t stat)
204
0
{
205
0
  LogString s = type;
206
0
  char err_buff[1024] = {0};
207
0
  apr_strerror(stat, err_buff, sizeof(err_buff));
208
0
  if (0 == err_buff[0] || 0 == strncmp(err_buff, "APR does not understand", 23))
209
0
  {
210
0
    s.append(LOG4CXX_STR(": error code "));
211
0
    StringHelper::toString(stat, s);
212
0
  }
213
0
  else
214
0
  {
215
0
    s.append(LOG4CXX_STR(" - "));
216
0
    std::string sMsg = err_buff;
217
0
    LOG4CXX_DECODE_CHAR(lsMsg, sMsg);
218
0
    s.append(lsMsg);
219
0
  }
220
0
  return s;
221
0
}
222
223
#if !LOG4CXX_LOGCHAR_IS_UTF8
224
std::string Exception::makeMessage(const char* type, log4cxx_status_t stat)
225
{
226
  std::string s = type;
227
  char err_buff[1024] = {0};
228
  apr_strerror(stat, err_buff, sizeof(err_buff));
229
  if (0 == err_buff[0] || 0 == strncmp(err_buff, "APR does not understand", 23))
230
  {
231
    s.append(": error code ");
232
    s.append(std::to_string(stat));
233
  }
234
  else
235
  {
236
    s.append(" - ");
237
    s.append(err_buff);
238
  }
239
  return s;
240
}
241
#endif
242
243
MissingResourceException::MissingResourceException(const LogString& key)
244
0
  : Exception(formatMessage(key))
245
0
{
246
0
}
247
248
249
MissingResourceException::MissingResourceException(const MissingResourceException& src)
250
0
  : Exception(src)
251
0
{
252
0
}
253
254
MissingResourceException& MissingResourceException::operator=(const MissingResourceException& src)
255
0
{
256
0
  Exception::operator=(src);
257
0
  return *this;
258
0
}
259
260
LogString MissingResourceException::formatMessage(const LogString& key)
261
0
{
262
0
  LogString s(LOG4CXX_STR("MissingResourceException: resource key = \""));
263
0
  s.append(key);
264
0
  s.append(LOG4CXX_STR("\"."));
265
0
  return s;
266
0
}
267
268
PoolException::PoolException(log4cxx_status_t stat)
269
0
  : Exception(formatMessage(stat))
270
0
{
271
0
}
272
273
PoolException::PoolException(const PoolException& src)
274
0
  : Exception(src)
275
0
{
276
0
}
277
278
PoolException& PoolException::operator=(const PoolException& src)
279
0
{
280
0
  Exception::operator=(src);
281
0
  return *this;
282
0
}
283
284
LogString PoolException::formatMessage(log4cxx_status_t stat)
285
0
{
286
0
  return makeMessage(LOG4CXX_STR("Pool exception"), stat);
287
0
}
288
289
290
TranscoderException::TranscoderException(log4cxx_status_t stat)
291
0
  : Exception(formatMessage(stat))
292
0
{
293
0
}
294
295
TranscoderException::TranscoderException(const TranscoderException& src)
296
0
  : Exception(src)
297
0
{
298
0
}
299
300
TranscoderException& TranscoderException::operator=(const TranscoderException& src)
301
0
{
302
0
  Exception::operator=(src);
303
0
  return *this;
304
0
}
305
306
LogString TranscoderException::formatMessage(log4cxx_status_t)
307
0
{
308
0
  return LOG4CXX_STR("Transcoder exception");
309
0
}
310
311
312
0
InterruptedException::InterruptedException() : Exception(LOG4CXX_STR("Thread was interrupted"))
313
0
{
314
0
}
315
316
InterruptedException::InterruptedException(log4cxx_status_t stat)
317
0
  : Exception(formatMessage(stat))
318
0
{
319
0
}
320
321
InterruptedException::InterruptedException(const InterruptedException& src)
322
0
  : Exception(src)
323
0
{
324
0
}
325
326
InterruptedException& InterruptedException::operator=(const InterruptedException& src)
327
0
{
328
0
  Exception::operator=(src);
329
0
  return *this;
330
0
}
331
332
LogString InterruptedException::formatMessage(log4cxx_status_t stat)
333
0
{
334
0
  LogString s(LOG4CXX_STR("InterruptedException: stat = "));
335
0
  StringHelper::toString(stat, s);
336
0
  return s;
337
0
}
338
339
ThreadException::ThreadException(log4cxx_status_t stat)
340
0
  : Exception(formatMessage(stat))
341
0
{
342
0
}
343
344
ThreadException::ThreadException(const LogString& msg)
345
0
  : Exception(msg)
346
0
{
347
0
}
348
349
ThreadException::ThreadException(const ThreadException& src)
350
0
  : Exception(src)
351
0
{
352
0
}
353
354
ThreadException& ThreadException::operator=(const ThreadException& src)
355
0
{
356
0
  Exception::operator=(src);
357
0
  return *this;
358
0
}
359
360
LogString ThreadException::formatMessage(log4cxx_status_t stat)
361
0
{
362
0
  return makeMessage(LOG4CXX_STR("Thread exception"), stat);
363
0
}
364
365
IllegalMonitorStateException::IllegalMonitorStateException(const LogString& msg1)
366
0
  : Exception(msg1)
367
0
{
368
0
}
369
370
IllegalMonitorStateException::IllegalMonitorStateException(const IllegalMonitorStateException& src)
371
0
  : Exception(src)
372
0
{
373
0
}
374
375
IllegalMonitorStateException& IllegalMonitorStateException::operator=(const IllegalMonitorStateException& src)
376
0
{
377
0
  Exception::operator=(src);
378
0
  return *this;
379
0
}
380
381
InstantiationException::InstantiationException(const LogString& msg1)
382
0
  : Exception(msg1)
383
0
{
384
0
}
385
386
InstantiationException::InstantiationException(const InstantiationException& src)
387
0
  : Exception(src)
388
0
{
389
0
}
390
391
InstantiationException& InstantiationException::operator=(const InstantiationException& src)
392
0
{
393
0
  Exception::operator=(src);
394
0
  return *this;
395
0
}
396
397
ClassNotFoundException::ClassNotFoundException(const LogString& className)
398
0
  : Exception(formatMessage(className))
399
0
{
400
0
}
401
402
ClassNotFoundException::ClassNotFoundException(const ClassNotFoundException& src)
403
0
  : Exception(src)
404
0
{
405
0
}
406
407
408
ClassNotFoundException& ClassNotFoundException::operator=(const ClassNotFoundException& src)
409
0
{
410
0
  Exception::operator=(src);
411
0
  return *this;
412
0
}
413
414
LogString ClassNotFoundException::formatMessage(const LogString& className)
415
0
{
416
0
  LogString s(LOG4CXX_STR("Class not found: "));
417
0
  s.append(className);
418
0
  return s;
419
0
}
420
421
422
NoSuchElementException::NoSuchElementException()
423
0
  : Exception(LOG4CXX_STR("No such element"))
424
0
{
425
0
}
426
427
NoSuchElementException::NoSuchElementException(const NoSuchElementException& src)
428
0
  : Exception(src)
429
0
{
430
0
}
431
432
NoSuchElementException& NoSuchElementException::operator=(const NoSuchElementException& src)
433
0
{
434
0
  Exception::operator=(src);
435
0
  return *this;
436
0
}
437
438
439
IllegalStateException::IllegalStateException()
440
0
  : Exception(LOG4CXX_STR("Illegal state"))
441
0
{
442
0
}
443
444
IllegalStateException::IllegalStateException(const IllegalStateException& src)
445
0
  : Exception(src)
446
0
{
447
0
}
448
449
IllegalStateException& IllegalStateException::operator=(const IllegalStateException& src)
450
0
{
451
0
  Exception::operator=(src);
452
0
  return *this;
453
0
}
454
455
0
SocketException::SocketException(const LogString& msg) : IOException(msg)
456
0
{
457
0
}
458
459
0
SocketException::SocketException(log4cxx_status_t status) : IOException(status)
460
0
{
461
0
}
462
463
SocketException::SocketException(const SocketException& src)
464
0
  : IOException(src)
465
0
{
466
0
}
467
468
SocketException& SocketException::operator=(const SocketException& src)
469
0
{
470
0
  IOException::operator=(src);
471
0
  return *this;
472
0
}
473
474
0
ConnectException::ConnectException(const LogString& msg) : SocketException(msg)
475
0
{
476
0
}
477
478
0
ConnectException::ConnectException(log4cxx_status_t status) : SocketException(status)
479
0
{
480
0
}
481
482
ConnectException::ConnectException(const ConnectException& src)
483
0
  : SocketException(src)
484
0
{
485
0
}
486
487
ConnectException& ConnectException::operator=(const ConnectException& src)
488
0
{
489
0
  SocketException::operator=(src);
490
0
  return *this;
491
0
}
492
493
0
ClosedChannelException::ClosedChannelException() : SocketException(LOG4CXX_STR("Attempt to write to closed socket"))
494
0
{
495
0
}
496
497
ClosedChannelException::ClosedChannelException(const ClosedChannelException& src)
498
0
  : SocketException(src)
499
0
{
500
0
}
501
502
ClosedChannelException& ClosedChannelException::operator=(const ClosedChannelException& src)
503
0
{
504
0
  SocketException::operator=(src);
505
0
  return *this;
506
0
}
507
508
0
BindException::BindException(log4cxx_status_t status) : SocketException(status)
509
0
{
510
0
}
511
512
BindException::BindException(const BindException& src)
513
0
  : SocketException(src)
514
0
{
515
0
}
516
517
BindException& BindException::operator=(const BindException& src)
518
0
{
519
0
  SocketException::operator=(src);
520
0
  return *this;
521
0
}
522
523
0
InterruptedIOException::InterruptedIOException(const LogString& msg) : IOException(msg)
524
0
{
525
0
}
526
527
InterruptedIOException::InterruptedIOException(const InterruptedIOException& src)
528
0
  : IOException(src)
529
0
{
530
0
}
531
532
InterruptedIOException& InterruptedIOException::operator=(const InterruptedIOException& src)
533
0
{
534
0
  IOException::operator=(src);
535
0
  return *this;
536
0
}
537
538
SocketTimeoutException::SocketTimeoutException()
539
0
  : InterruptedIOException(LOG4CXX_STR("SocketTimeoutException"))
540
0
{
541
0
}
542
543
SocketTimeoutException::SocketTimeoutException(const SocketTimeoutException& src)
544
0
  : InterruptedIOException(src)
545
0
{
546
0
}
547
548
SocketTimeoutException& SocketTimeoutException::operator=(const SocketTimeoutException& src)
549
0
{
550
0
  InterruptedIOException::operator=(src);
551
0
  return *this;
552
0
}