diff --git a/source-code/ErrorHandling/Exceptions/CMakeLists.txt b/source-code/ErrorHandling/Exceptions/CMakeLists.txt new file mode 100644 index 0000000..5e1d34d --- /dev/null +++ b/source-code/ErrorHandling/Exceptions/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.20) + +project(exceptions LANGUAGES CXX) + +set(CMAKE_CXX_STANDARD 23) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + +add_executable(fac.exe fac.cpp) diff --git a/source-code/ErrorHandling/Exceptions/README.md b/source-code/ErrorHandling/Exceptions/README.md new file mode 100644 index 0000000..c73d3b7 --- /dev/null +++ b/source-code/ErrorHandling/Exceptions/README.md @@ -0,0 +1,10 @@ +# Expected + +Illustrates how to use exceptoin to do error handling. + +## What is it? + +1. `fac.cpp`: C++ application that reads an argument from the command line, + validates the value, computes the factorial and displays the output or + the error message. +1. `CMakeLists.txt`: CMake file to build the applications. diff --git a/source-code/ErrorHandling/fac.cpp b/source-code/ErrorHandling/Exceptions/fac.cpp similarity index 100% rename from source-code/ErrorHandling/fac.cpp rename to source-code/ErrorHandling/Exceptions/fac.cpp diff --git a/source-code/ErrorHandling/Makefile b/source-code/ErrorHandling/Makefile deleted file mode 100644 index 7e10d4b..0000000 --- a/source-code/ErrorHandling/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -CXX = g++ -CXXFLAGS = -std=c++14 -g -O2 -Wall -Wextra -LDLIBS = -lm - -all: fac.exe - -%.exe: %.o - $(CXX) $(CXXFLAGS) -o $@ $< $(LDLIBS) - -%.o: %.cpp - $(CXX) $(CXXFLAGS) -c -o $@ $< - -clean: - $(RM) $(wildcard *.exe) $(wildcard *.o) - $(RM) core $(wildcard core.) diff --git a/source-code/ErrorHandling/README.md b/source-code/ErrorHandling/README.md index 56625bc..d21219d 100644 --- a/source-code/ErrorHandling/README.md +++ b/source-code/ErrorHandling/README.md @@ -4,8 +4,7 @@ Code illustrations for chapter 3, Modularity in Stroustrup's "A tour of C++" on error handling using exceptions. # What is it? -1. `fac.cpp`: illustrates exception handling. -1. `Makefile`: make file for these examples. -1. `Expected`: illustrates error handling using `std::expected`. +1. `Exceptions`: illustration of error handling with exceptions. 1. `MemoryLeak`: illustrates how inappropriately handled exceptions can lead to memory leaks, and how to fix that. +1. `Expected`: illustrates error handling using `std::expected`.