Skip to content

Commit 30c2048

Browse files
committed
Updates from pull request cpp-tutor#4
1 parent 94990bf commit 30c2048

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

headers/04-noexcept.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@
44
#include <stdexcept>
55
using namespace std;
66

7-
int throw_if_zero(int i) noexcept {
7+
void throw_if_zero(int i) noexcept {
88
if (!i) {
99
throw runtime_error("found a zero");
1010
}
1111
println("throw_if_zero(): {}", i);
1212
}
1313

1414
int main() {
15-
cout << "Entering main()\n";
15+
println("Entering main()");
1616
try {
1717
throw_if_zero(1);
1818
throw_if_zero(0);
1919
}
20-
catch(...) {
21-
println("Caught an exception!");
20+
catch(exception& e) {
21+
println("Caught an exception: {}", e.what());
2222
}
23-
println("Leaving main()\n");
23+
println("Leaving main()");
2424
}

modules/04-noexcept.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@
33
import std;
44
using namespace std;
55

6-
int throw_if_zero(int i) noexcept {
6+
void throw_if_zero(int i) noexcept {
77
if (!i) {
88
throw runtime_error("found a zero");
99
}
1010
println("throw_if_zero(): {}", i);
1111
}
1212

1313
int main() {
14-
cout << "Entering main()\n";
14+
println("Entering main()");
1515
try {
1616
throw_if_zero(1);
1717
throw_if_zero(0);
1818
}
19-
catch(...) {
20-
println("Caught an exception!");
19+
catch(exception& e) {
20+
println("Caught an exception: {}", e.what());
2121
}
22-
println("Leaving main()\n");
22+
println("Leaving main()");
2323
}

0 commit comments

Comments
 (0)