Skip to content

Commit 2133a5d

Browse files
committed
Improve error message
1 parent 8ab4575 commit 2133a5d

2 files changed

Lines changed: 20 additions & 20 deletions

File tree

lib/checkexceptionsafety.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,12 +319,12 @@ void CheckExceptionSafety::nothrowThrows()
319319

320320
void CheckExceptionSafety::noexceptThrowError(const Token * const tok)
321321
{
322-
reportError(tok, Severity::error, "throwInNoexceptFunction", "Exception thrown in function declared not to throw exceptions.", CWE398, Certainty::normal);
322+
reportError(tok, Severity::error, "throwInNoexceptFunction", "Unhandled exception thrown in function declared not to throw exceptions.", CWE398, Certainty::normal);
323323
}
324324

325325
void CheckExceptionSafety::entryPointThrowError(const Token * const tok)
326326
{
327-
reportError(tok, Severity::error, "throwInEntryPoint", "Exception thrown in function that is an entry point.", CWE398, Certainty::normal);
327+
reportError(tok, Severity::error, "throwInEntryPoint", "Unhandled exception thrown in function that is an entry point.", CWE398, Certainty::normal);
328328
}
329329

330330
//--------------------------------------------------------------------------

test/testexceptionsafety.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class TestExceptionSafety : public TestFixture {
8787
" }\n"
8888
"};");
8989
ASSERT_EQUALS("[test.cpp:3:9]: (warning) Class x is not safe, destructor throws exception [exceptThrowInDestructor]\n"
90-
"[test.cpp:3:9]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\n", errout_str());
90+
"[test.cpp:3:9]: (error) Unhandled exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\n", errout_str());
9191

9292
check("class x {\n"
9393
" ~x();\n"
@@ -96,7 +96,7 @@ class TestExceptionSafety : public TestFixture {
9696
" throw e;\n"
9797
"}");
9898
ASSERT_EQUALS("[test.cpp:5:5]: (warning) Class x is not safe, destructor throws exception [exceptThrowInDestructor]\n"
99-
"[test.cpp:5:5]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\n", errout_str());
99+
"[test.cpp:5:5]: (error) Unhandled exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\n", errout_str());
100100

101101
// #3858 - throwing exception in try block in destructor.
102102
check("class x {\n"
@@ -116,7 +116,7 @@ class TestExceptionSafety : public TestFixture {
116116
" }\n"
117117
" }\n"
118118
"}");
119-
ASSERT_EQUALS("[test.cpp:4:13]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\n", errout_str());
119+
ASSERT_EQUALS("[test.cpp:4:13]: (error) Unhandled exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\n", errout_str());
120120

121121
// #11031 should not warn when noexcept false
122122
check("class A {\n"
@@ -349,9 +349,9 @@ class TestExceptionSafety : public TestFixture {
349349
"void func4() noexcept(false) { throw 1; }\n"
350350
"void func5() noexcept(true) { func1(); }\n"
351351
"void func6() noexcept(false) { func1(); }");
352-
ASSERT_EQUALS("[test.cpp:2:25]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\n"
353-
"[test.cpp:3:31]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\n"
354-
"[test.cpp:5:31]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\n", errout_str());
352+
ASSERT_EQUALS("[test.cpp:2:25]: (error) Unhandled exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\n"
353+
"[test.cpp:3:31]: (error) Unhandled exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\n"
354+
"[test.cpp:5:31]: (error) Unhandled exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\n", errout_str());
355355

356356
// avoid false positives
357357
check("const char *func() noexcept { return 0; }\n"
@@ -365,8 +365,8 @@ class TestExceptionSafety : public TestFixture {
365365
"void func3() throw(int) { throw 1; }\n"
366366
"void func4() throw() { func1(); }\n"
367367
"void func5() throw(int) { func1(); }");
368-
ASSERT_EQUALS("[test.cpp:2:24]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\n"
369-
"[test.cpp:4:24]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\n", errout_str());
368+
ASSERT_EQUALS("[test.cpp:2:24]: (error) Unhandled exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\n"
369+
"[test.cpp:4:24]: (error) Unhandled exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\n", errout_str());
370370

371371
// avoid false positives
372372
check("const char *func() throw() { return 0; }");
@@ -405,7 +405,7 @@ class TestExceptionSafety : public TestFixture {
405405
"{\n"
406406
" f();\n"
407407
"}\n", dinit(CheckOptions, $.inconclusive = true));
408-
ASSERT_EQUALS("[test.cpp:4:5]: (error) Exception thrown in function that is an entry point. [throwInEntryPoint]\n", errout_str());
408+
ASSERT_EQUALS("[test.cpp:4:5]: (error) Unhandled exception thrown in function that is an entry point. [throwInEntryPoint]\n", errout_str());
409409
}
410410

411411
void unhandledExceptionSpecification3() {
@@ -422,24 +422,24 @@ class TestExceptionSafety : public TestFixture {
422422
"}\n";
423423

424424
check(code, dinit(CheckOptions, $.inconclusive = true));
425-
ASSERT_EQUALS("[test.cpp:10:5]: (error) Exception thrown in function that is an entry point. [throwInEntryPoint]\n"
425+
ASSERT_EQUALS("[test.cpp:10:5]: (error) Unhandled exception thrown in function that is an entry point. [throwInEntryPoint]\n"
426426
"[test.cpp:3:5] -> [test.cpp:1:6]: (style, inconclusive) Unhandled exception specification when calling function f(). [unhandledExceptionSpecification]\n"
427427
"[test.cpp:6:5] -> [test.cpp:1:6]: (style, inconclusive) Unhandled exception specification when calling function f(). [unhandledExceptionSpecification]\n", errout_str());
428428

429429
const Settings s = settingsBuilder().library("gnu.cfg").build();
430430
check(code, dinit(CheckOptions, $.inconclusive = true, $.s = &s));
431-
ASSERT_EQUALS("[test.cpp:3:5]: (error) Exception thrown in function that is an entry point. [throwInEntryPoint]\n"
432-
"[test.cpp:6:5]: (error) Exception thrown in function that is an entry point. [throwInEntryPoint]\n"
433-
"[test.cpp:10:5]: (error) Exception thrown in function that is an entry point. [throwInEntryPoint]\n",
431+
ASSERT_EQUALS("[test.cpp:3:5]: (error) Unhandled exception thrown in function that is an entry point. [throwInEntryPoint]\n"
432+
"[test.cpp:6:5]: (error) Unhandled exception thrown in function that is an entry point. [throwInEntryPoint]\n"
433+
"[test.cpp:10:5]: (error) Unhandled exception thrown in function that is an entry point. [throwInEntryPoint]\n",
434434
errout_str());
435435
}
436436

437437
void nothrowAttributeThrow() {
438438
check("void func1() throw(int) { throw 1; }\n"
439439
"void func2() __attribute((nothrow)); void func2() { throw 1; }\n"
440440
"void func3() __attribute((nothrow)); void func3() { func1(); }");
441-
ASSERT_EQUALS("[test.cpp:2:53]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\n"
442-
"[test.cpp:3:53]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\n", errout_str());
441+
ASSERT_EQUALS("[test.cpp:2:53]: (error) Unhandled exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\n"
442+
"[test.cpp:3:53]: (error) Unhandled exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\n", errout_str());
443443

444444
// avoid false positives
445445
check("const char *func() __attribute((nothrow)); void func1() { return 0; }");
@@ -459,8 +459,8 @@ class TestExceptionSafety : public TestFixture {
459459
check("void func1() throw(int) { throw 1; }\n"
460460
"void __declspec(nothrow) func2() { throw 1; }\n"
461461
"void __declspec(nothrow) func3() { func1(); }");
462-
ASSERT_EQUALS("[test.cpp:2:36]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\n"
463-
"[test.cpp:3:36]: (error) Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\n", errout_str());
462+
ASSERT_EQUALS("[test.cpp:2:36]: (error) Unhandled exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\n"
463+
"[test.cpp:3:36]: (error) Unhandled exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]\n", errout_str());
464464

465465
// avoid false positives
466466
check("const char *func() __attribute((nothrow)); void func1() { return 0; }");
@@ -504,7 +504,7 @@ class TestExceptionSafety : public TestFixture {
504504
"int main(int argc, char* argv[]) {\n"
505505
" f(argc);\n"
506506
"}\n");
507-
ASSERT_EQUALS("[test.cpp:6:5]: (error) Exception thrown in function that is an entry point. [throwInEntryPoint]\n",
507+
ASSERT_EQUALS("[test.cpp:6:5]: (error) Unhandled exception thrown in function that is an entry point. [throwInEntryPoint]\n",
508508
errout_str());
509509

510510
check("void f(int i) {\n"

0 commit comments

Comments
 (0)