uni

University stuff
git clone git://git.christosmarg.xyz/uni-assignments.git
Log | Files | Refs | README | LICENSE

commit cf2974b0fa72c58b87e780a5984205cb16aae286
parent 8284b73c34c68d2ae3b795b44818d611ae2331c2
Author: Christos Margiolis <christos@margiolis.net>
Date:   Sat,  2 May 2020 18:32:59 +0300

more exception handling

Diffstat:
Massignment-2.4-inheritance/bin/inheritance | 0
Massignment-2.4-inheritance/obj/app.o | 0
Massignment-2.4-inheritance/obj/game.o | 0
Massignment-2.4-inheritance/obj/main.o | 0
Massignment-2.4-inheritance/obj/manufacturer.o | 0
Massignment-2.4-inheritance/obj/office.o | 0
Massignment-2.4-inheritance/res/manfout.csv | 4++--
Massignment-2.4-inheritance/src/app.cpp | 25+++++++++++++++++++++++--
Massignment-2.4-inheritance/src/app.h | 1+
Massignment-2.4-inheritance/src/game.cpp | 12+++++++++++-
Massignment-2.4-inheritance/src/main.cpp | 4++--
Massignment-2.4-inheritance/src/manufacturer.cpp | 16+++++++++++++---
Massignment-2.4-inheritance/src/manufacturer.h | 2+-
Massignment-2.4-inheritance/src/review.h | 2+-
14 files changed, 54 insertions(+), 12 deletions(-)

diff --git a/assignment-2.4-inheritance/bin/inheritance b/assignment-2.4-inheritance/bin/inheritance Binary files differ. diff --git a/assignment-2.4-inheritance/obj/app.o b/assignment-2.4-inheritance/obj/app.o Binary files differ. diff --git a/assignment-2.4-inheritance/obj/game.o b/assignment-2.4-inheritance/obj/game.o Binary files differ. diff --git a/assignment-2.4-inheritance/obj/main.o b/assignment-2.4-inheritance/obj/main.o Binary files differ. diff --git a/assignment-2.4-inheritance/obj/manufacturer.o b/assignment-2.4-inheritance/obj/manufacturer.o Binary files differ. diff --git a/assignment-2.4-inheritance/obj/office.o b/assignment-2.4-inheritance/obj/office.o Binary files differ. diff --git a/assignment-2.4-inheritance/res/manfout.csv b/assignment-2.4-inheritance/res/manfout.csv @@ -1,6 +1,6 @@ SN,Name,Email -1234,GNU,gnu@gnu.com -5678,Chris,chris@cm.com +124,GNU,gnu@gnu.com +568,Chris,chris@cm.com 741,Riot,riot@riot.com 987,Valve,valve@valve.com 456,GNU,gnu@gnu.com diff --git a/assignment-2.4-inheritance/src/app.cpp b/assignment-2.4-inheritance/src/app.cpp @@ -7,8 +7,29 @@ App::App(const char *serialnum, const std::string& name, const std::string& os, Manufacturer *manf, int price) :serialnum(convsn(serialnum)), name(name), os(os), manf(manf), price(price) { - try {if (price < 0) throw price;} - catch (int price) {throw std::runtime_error("Price can't have negative value.");} + try + { + if (strcmp(serialnum, "") == 0) throw serialnum; + if (name.empty() || name == "") throw name; + if (os.empty() || os == "") throw os; + if (price < 0) throw price; + } + catch (const char *serialnum) + { + throw std::runtime_error("Empty app serial number."); + } + catch (const std::string& name) + { + throw std::runtime_error("Empty app name."); + } + catch (const std::string& os) + { + throw std::runtime_error("Empty OS name."); + } + catch (int price) + { + throw std::runtime_error("Price can't have negative value."); + } } App::~App() diff --git a/assignment-2.4-inheritance/src/app.h b/assignment-2.4-inheritance/src/app.h @@ -1,6 +1,7 @@ #ifndef APP_H #define APP_H +#include <stdexcept> #include <string> #include <string.h> #include <vector> diff --git a/assignment-2.4-inheritance/src/game.cpp b/assignment-2.4-inheritance/src/game.cpp @@ -6,7 +6,17 @@ Game::Game() Game::Game(const char *serialnum, const std::string& name, const std::string& os, Manufacturer *manf, int price, const std::string& genre, bool online) - :App(serialnum, name, os, manf, price), genre(genre), online(online) {} + :App(serialnum, name, os, manf, price), genre(genre), online(online) +{ + try + { + if (genre.empty() || genre == "") throw genre; + } + catch (const std::string& genre) + { + throw std::runtime_error("Empty game genre."); + } +} const std::string Game::get_genre() const { diff --git a/assignment-2.4-inheritance/src/main.cpp b/assignment-2.4-inheritance/src/main.cpp @@ -45,8 +45,8 @@ std::ostream& operator<< (std::ostream& stream, const AppSystem& sys) int main(int argc, char **argv) { AppSystem sys; - Manufacturer *gnu = new Manufacturer("1234", "GNU", "gnu@gnu.com"); - Manufacturer *cm = new Manufacturer("5678", "Chris", "chris@cm.com"); + Manufacturer *gnu = new Manufacturer("124", "GNU", "gnu@gnu.com"); + Manufacturer *cm = new Manufacturer("568", "Chris", "chris@cm.com"); sys += gnu; sys += cm; if (!sys.read_data<Manufacturer>("res/manfdata.csv")) return -1; diff --git a/assignment-2.4-inheritance/src/manufacturer.cpp b/assignment-2.4-inheritance/src/manufacturer.cpp @@ -9,12 +9,22 @@ Manufacturer::Manufacturer(const char *serialnum, const char *name, { try { - if (email.find("@") == std::string::npos) - throw email; + if (strcmp(serialnum, "") == 0) throw serialnum; + if (strcmp(name, "") == 0) throw name; + if (email.empty() || email == "" || + email.find("@") == std::string::npos) throw email; + } + catch (const char *serialnum) + { + throw std::runtime_error("Empty manufacturer serial number."); + } + catch (const char *name) + { + throw std::runtime_error("Empty manufacturer name."); } catch (const std::string& email) { - std::string err = "Invalid email format. (" + email + ")"; + std::string err = "Invalid email. Empty email/Missing \'@\'"; throw std::runtime_error(err); } } diff --git a/assignment-2.4-inheritance/src/manufacturer.h b/assignment-2.4-inheritance/src/manufacturer.h @@ -1,9 +1,9 @@ #ifndef MANUFACTURER_H #define MANUFACTURER_H +#include <stdexcept> #include <string> #include <string.h> -#include <stdexcept> class Manufacturer { diff --git a/assignment-2.4-inheritance/src/review.h b/assignment-2.4-inheritance/src/review.h @@ -1,8 +1,8 @@ #ifndef REVIEW_H #define REVIEW_H -#include <string> #include <stdexcept> +#include <string> class Review {