add Chapter01 examples

This commit is contained in:
Amar Mahmutbegovic
2024-04-27 20:43:40 +02:00
parent fb4983465f
commit de6d74e093
12 changed files with 435 additions and 0 deletions

31
Chapter01/exceptions.cpp Normal file
View File

@@ -0,0 +1,31 @@
#include <cstdio>
struct A {
A() { printf("A is created!\r\n"); }
~A() { printf("A is destroyed!\r\n"); }
};
struct B {
B() { printf("B is created!\r\n"); }
~B() { printf("B is destroyed!\r\n"); }
};
void bar() {
B b;
throw 0;
}
void foo() {
A a;
bar();
A a1;
}
int main() {
try {
foo();
} catch (int &p) {
printf("Catching an exception!\r\n");
}
return 0;
}