From 3cbb1de4ffdc36eaa7464e2123d15e152a4690fa Mon Sep 17 00:00:00 2001 From: Lev Date: Tue, 31 Aug 2021 22:56:15 -0500 Subject: [PATCH] Add types of error examples --- .../11.2.1 Types of errors/compile-error.cpp | 10 ++++++++++ .../Topic 4/11.2.1 Types of errors/link-error.cpp | 13 +++++++++++++ .../Topic 4/11.2.1 Types of errors/non-error.cpp | 9 +++++++++ .../11.2.1 Types of errors/runtime-error.cpp | 12 ++++++++++++ .../Topic 4/11.2.1 Types of errors/syntax-error.cpp | 5 +++++ 5 files changed, 49 insertions(+) create mode 100644 CM2010 Software Design and Development/Topic 4/11.2.1 Types of errors/compile-error.cpp create mode 100644 CM2010 Software Design and Development/Topic 4/11.2.1 Types of errors/link-error.cpp create mode 100644 CM2010 Software Design and Development/Topic 4/11.2.1 Types of errors/non-error.cpp create mode 100644 CM2010 Software Design and Development/Topic 4/11.2.1 Types of errors/runtime-error.cpp create mode 100644 CM2010 Software Design and Development/Topic 4/11.2.1 Types of errors/syntax-error.cpp diff --git a/CM2010 Software Design and Development/Topic 4/11.2.1 Types of errors/compile-error.cpp b/CM2010 Software Design and Development/Topic 4/11.2.1 Types of errors/compile-error.cpp new file mode 100644 index 0000000..a8d88fe --- /dev/null +++ b/CM2010 Software Design and Development/Topic 4/11.2.1 Types of errors/compile-error.cpp @@ -0,0 +1,10 @@ +int test() +{ + return 1; +} + +int main() +{ + test(128); + return 0; +} \ No newline at end of file diff --git a/CM2010 Software Design and Development/Topic 4/11.2.1 Types of errors/link-error.cpp b/CM2010 Software Design and Development/Topic 4/11.2.1 Types of errors/link-error.cpp new file mode 100644 index 0000000..2fa0faf --- /dev/null +++ b/CM2010 Software Design and Development/Topic 4/11.2.1 Types of errors/link-error.cpp @@ -0,0 +1,13 @@ +int test(); // Function signature + +// The implementation fixes the link-build error +// in test() +// { +// return 10; +// } + +int main() +{ + test(); + return 0; +} \ No newline at end of file diff --git a/CM2010 Software Design and Development/Topic 4/11.2.1 Types of errors/non-error.cpp b/CM2010 Software Design and Development/Topic 4/11.2.1 Types of errors/non-error.cpp new file mode 100644 index 0000000..a7150c8 --- /dev/null +++ b/CM2010 Software Design and Development/Topic 4/11.2.1 Types of errors/non-error.cpp @@ -0,0 +1,9 @@ +int calculateArea(int width, in height) +{ + return width * height; +} +int main() +{ + int area = calculateArea(-10, -12); // non-sensical because a rectangle can't have negative dimensions + return 0; +} \ No newline at end of file diff --git a/CM2010 Software Design and Development/Topic 4/11.2.1 Types of errors/runtime-error.cpp b/CM2010 Software Design and Development/Topic 4/11.2.1 Types of errors/runtime-error.cpp new file mode 100644 index 0000000..6466a20 --- /dev/null +++ b/CM2010 Software Design and Development/Topic 4/11.2.1 Types of errors/runtime-error.cpp @@ -0,0 +1,12 @@ +#include +int divide(int x, int y) +{ + return x/y; +} + +int main() +{ + int div = divide(10, 0); // can't divide by zero + std::cout << div << std::endl; + return 0; +} \ No newline at end of file diff --git a/CM2010 Software Design and Development/Topic 4/11.2.1 Types of errors/syntax-error.cpp b/CM2010 Software Design and Development/Topic 4/11.2.1 Types of errors/syntax-error.cpp new file mode 100644 index 0000000..3daa23c --- /dev/null +++ b/CM2010 Software Design and Development/Topic 4/11.2.1 Types of errors/syntax-error.cpp @@ -0,0 +1,5 @@ +int main() +{ + int @!#* = 10; + return 0; +} \ No newline at end of file