Coverage Report

Created: 2026-05-30 06:57

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
26
using namespace LOG4CXX_NS;
27
using namespace LOG4CXX_NS::helpers;
28
29
Exception::Exception(const LogString& msg1)
30
0
{
31
0
  LOG4CXX_ENCODE_CHAR(m, msg1);
32
0
  msg = m;
33
0
}
34
35
Exception::Exception(const char* m)
36
0
{
37
0
  msg = (m ? std::string(m) : std::string());
38
0
}
39
40
41
0
Exception::Exception(const Exception& src) : std::exception()
42
0
{
43
0
  msg = src.msg;
44
0
}
45
46
Exception& Exception::operator=(const Exception& src)
47
0
{
48
0
  msg = src.msg;
49
0
  return *this;
50
0
}
51
52
const char* Exception::what() const throw()
53
0
{
54
0
  return msg.c_str();
55
0
}
56
57
RuntimeException::RuntimeException(log4cxx_status_t stat)
58
0
  : Exception(formatMessage(stat))
59
0
{
60
0
}
61
62
RuntimeException::RuntimeException(const LogString& msg1)
63
0
  : Exception(msg1)
64
0
{
65
0
}
66
67
RuntimeException::RuntimeException(const RuntimeException& src)
68
0
  : Exception(src)
69
0
{
70
0
}
71
72
RuntimeException& RuntimeException::operator=(const RuntimeException& src)
73
0
{
74
0
  Exception::operator=(src);
75
0
  return *this;
76
0
}
77
78
LogString RuntimeException::formatMessage(log4cxx_status_t stat)
79
0
{
80
0
  LogString s(LOG4CXX_STR("RuntimeException: return code = "));
81
0
  StringHelper::toString(stat, s);
82
0
  return s;
83
0
}
84
85
NullPointerException::NullPointerException(const LogString& msg1)
86
0
  : RuntimeException(msg1 + LOG4CXX_STR(" may not be null"))
87
0
{
88
0
}
89
90
NullPointerException::NullPointerException(const NullPointerException& src)
91
0
  : RuntimeException(src)
92
0
{
93
0
}
94
95
NullPointerException& NullPointerException::operator=(const NullPointerException& src)
96
0
{
97
0
  RuntimeException::operator=(src);
98
0
  return *this;
99
0
}
100
101
IllegalArgumentException::IllegalArgumentException(const LogString& msg1)
102
0
  : RuntimeException(msg1)
103
0
{
104
0
}
105
106
IllegalArgumentException::IllegalArgumentException(const IllegalArgumentException& src)
107
0
  : RuntimeException(src)
108
0
{
109
0
}
110
111
IllegalArgumentException& IllegalArgumentException::operator=(const IllegalArgumentException& src)
112
0
{
113
0
  RuntimeException::operator=(src);
114
0
  return *this;
115
0
}
116
117
IOException::IOException()
118
0
  : Exception(LOG4CXX_STR("IO exception"))
119
0
{
120
0
}
121
122
IOException::IOException(log4cxx_status_t stat)
123
0
  : Exception(formatMessage(stat))
124
0
{
125
0
}
126
127
IOException::IOException(const LogString& type, log4cxx_status_t stat)
128
0
  : Exception(makeMessage(type, stat))
129
0
{
130
0
}
131
132
#if !LOG4CXX_LOGCHAR_IS_UTF8
133
IOException::IOException(const char* type, log4cxx_status_t stat)
134
0
  : Exception(makeMessage(type, stat).c_str())
135
0
{
136
0
}
137
#endif
138
139
IOException::IOException(const char* msg1)
140
0
  : Exception(msg1)
141
0
{
142
0
}
143
144
IOException::IOException(const LogString& msg1)
145
0
  : Exception(msg1)
146
0
{
147
0
}
148
149
IOException::IOException(const IOException& src)
150
0
  : Exception(src)
151
0
{
152
0
}
153
154
IOException& IOException::operator=(const IOException& src)
155
0
{
156
0
  Exception::operator=(src);
157
0
  return *this;
158
0
}
159
160
LogString IOException::formatMessage(log4cxx_status_t stat)
161
0
{
162
0
  return makeMessage(LOG4CXX_STR("IO Exception"), stat);
163
0
}
164
165
LogString Exception::makeMessage(const LogString& type, log4cxx_status_t stat)
166
0
{
167
0
  LogString s = type;
168
0
  char err_buff[1024] = {0};
169
0
  apr_strerror(stat, err_buff, sizeof(err_buff));
170
0
  if (0 == err_buff[0] || 0 == strncmp(err_buff, "APR does not understand", 23))
171
0
  {
172
0
    s.append(LOG4CXX_STR(": error code "));
173
0
    StringHelper::toString(stat, s);
174
0
  }
175
0
  else
176
0
  {
177
0
    s.append(LOG4CXX_STR(" - "));
178
0
    std::string sMsg = err_buff;
179
0
    LOG4CXX_DECODE_CHAR(lsMsg, sMsg);
180
0
    s.append(lsMsg);
181
0
  }
182
0
  return s;
183
0
}
184
185
#if !LOG4CXX_LOGCHAR_IS_UTF8
186
std::string Exception::makeMessage(const char* type, log4cxx_status_t stat)
187
0
{
188
0
  std::string s = type;
189
0
  char err_buff[1024] = {0};
190
0
  apr_strerror(stat, err_buff, sizeof(err_buff));
191
0
  if (0 == err_buff[0] || 0 == strncmp(err_buff, "APR does not understand", 23))
192
0
  {
193
0
    s.append(": error code ");
194
0
    s.append(std::to_string(stat));
195
0
  }
196
0
  else
197
0
  {
198
0
    s.append(" - ");
199
0
    s.append(err_buff);
200
0
  }
201
0
  return s;
202
0
}
203
#endif
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
  StringHelper::toString(stat, s);
298
0
  return s;
299
0
}
300
301
ThreadException::ThreadException(log4cxx_status_t stat)
302
0
  : Exception(formatMessage(stat))
303
0
{
304
0
}
305
306
ThreadException::ThreadException(const LogString& msg)
307
0
  : Exception(msg)
308
0
{
309
0
}
310
311
ThreadException::ThreadException(const ThreadException& src)
312
0
  : Exception(src)
313
0
{
314
0
}
315
316
ThreadException& ThreadException::operator=(const ThreadException& src)
317
0
{
318
0
  Exception::operator=(src);
319
0
  return *this;
320
0
}
321
322
LogString ThreadException::formatMessage(log4cxx_status_t stat)
323
0
{
324
0
  return makeMessage(LOG4CXX_STR("Thread exception"), stat);
325
0
}
326
327
IllegalMonitorStateException::IllegalMonitorStateException(const LogString& msg1)
328
0
  : Exception(msg1)
329
0
{
330
0
}
331
332
IllegalMonitorStateException::IllegalMonitorStateException(const IllegalMonitorStateException& src)
333
0
  : Exception(src)
334
0
{
335
0
}
336
337
IllegalMonitorStateException& IllegalMonitorStateException::operator=(const IllegalMonitorStateException& src)
338
0
{
339
0
  Exception::operator=(src);
340
0
  return *this;
341
0
}
342
343
InstantiationException::InstantiationException(const LogString& msg1)
344
0
  : Exception(msg1)
345
0
{
346
0
}
347
348
InstantiationException::InstantiationException(const InstantiationException& src)
349
0
  : Exception(src)
350
0
{
351
0
}
352
353
InstantiationException& InstantiationException::operator=(const InstantiationException& src)
354
0
{
355
0
  Exception::operator=(src);
356
0
  return *this;
357
0
}
358
359
ClassNotFoundException::ClassNotFoundException(const LogString& className)
360
0
  : Exception(formatMessage(className))
361
0
{
362
0
}
363
364
ClassNotFoundException::ClassNotFoundException(const ClassNotFoundException& src)
365
0
  : Exception(src)
366
0
{
367
0
}
368
369
370
ClassNotFoundException& ClassNotFoundException::operator=(const ClassNotFoundException& src)
371
0
{
372
0
  Exception::operator=(src);
373
0
  return *this;
374
0
}
375
376
LogString ClassNotFoundException::formatMessage(const LogString& className)
377
0
{
378
0
  LogString s(LOG4CXX_STR("Class not found: "));
379
0
  s.append(className);
380
0
  return s;
381
0
}
382
383
384
NoSuchElementException::NoSuchElementException()
385
0
  : Exception(LOG4CXX_STR("No such element"))
386
0
{
387
0
}
388
389
NoSuchElementException::NoSuchElementException(const NoSuchElementException& src)
390
0
  : Exception(src)
391
0
{
392
0
}
393
394
NoSuchElementException& NoSuchElementException::operator=(const NoSuchElementException& src)
395
0
{
396
0
  Exception::operator=(src);
397
0
  return *this;
398
0
}
399
400
401
IllegalStateException::IllegalStateException()
402
0
  : Exception(LOG4CXX_STR("Illegal state"))
403
0
{
404
0
}
405
406
IllegalStateException::IllegalStateException(const IllegalStateException& src)
407
0
  : Exception(src)
408
0
{
409
0
}
410
411
IllegalStateException& IllegalStateException::operator=(const IllegalStateException& src)
412
0
{
413
0
  Exception::operator=(src);
414
0
  return *this;
415
0
}
416
417
0
SocketException::SocketException(const LogString& msg) : IOException(msg)
418
0
{
419
0
}
420
421
0
SocketException::SocketException(log4cxx_status_t status) : IOException(status)
422
0
{
423
0
}
424
425
SocketException::SocketException(const SocketException& src)
426
0
  : IOException(src)
427
0
{
428
0
}
429
430
SocketException& SocketException::operator=(const SocketException& src)
431
0
{
432
0
  IOException::operator=(src);
433
0
  return *this;
434
0
}
435
436
0
ConnectException::ConnectException(const LogString& msg) : SocketException(msg)
437
0
{
438
0
}
439
440
0
ConnectException::ConnectException(log4cxx_status_t status) : SocketException(status)
441
0
{
442
0
}
443
444
ConnectException::ConnectException(const ConnectException& src)
445
0
  : SocketException(src)
446
0
{
447
0
}
448
449
ConnectException& ConnectException::operator=(const ConnectException& src)
450
0
{
451
0
  SocketException::operator=(src);
452
0
  return *this;
453
0
}
454
455
0
ClosedChannelException::ClosedChannelException() : SocketException(LOG4CXX_STR("Attempt to write to closed socket"))
456
0
{
457
0
}
458
459
ClosedChannelException::ClosedChannelException(const ClosedChannelException& src)
460
0
  : SocketException(src)
461
0
{
462
0
}
463
464
ClosedChannelException& ClosedChannelException::operator=(const ClosedChannelException& src)
465
0
{
466
0
  SocketException::operator=(src);
467
0
  return *this;
468
0
}
469
470
0
BindException::BindException(log4cxx_status_t status) : SocketException(status)
471
0
{
472
0
}
473
474
BindException::BindException(const BindException& src)
475
0
  : SocketException(src)
476
0
{
477
0
}
478
479
BindException& BindException::operator=(const BindException& src)
480
0
{
481
0
  SocketException::operator=(src);
482
0
  return *this;
483
0
}
484
485
0
InterruptedIOException::InterruptedIOException(const LogString& msg) : IOException(msg)
486
0
{
487
0
}
488
489
InterruptedIOException::InterruptedIOException(const InterruptedIOException& src)
490
0
  : IOException(src)
491
0
{
492
0
}
493
494
InterruptedIOException& InterruptedIOException::operator=(const InterruptedIOException& src)
495
0
{
496
0
  IOException::operator=(src);
497
0
  return *this;
498
0
}
499
500
SocketTimeoutException::SocketTimeoutException()
501
0
  : InterruptedIOException(LOG4CXX_STR("SocketTimeoutException"))
502
0
{
503
0
}
504
505
SocketTimeoutException::SocketTimeoutException(const SocketTimeoutException& src)
506
0
  : InterruptedIOException(src)
507
0
{
508
0
}
509
510
SocketTimeoutException& SocketTimeoutException::operator=(const SocketTimeoutException& src)
511
0
{
512
0
  InterruptedIOException::operator=(src);
513
0
  return *this;
514
0
}