From 5017d958c5254e9c61553e804778ed6142cf50ae Mon Sep 17 00:00:00 2001 From: smh Date: Sat, 2 Sep 2023 15:42:48 +0800 Subject: [PATCH] exceptions added --- Exceptions.cpp | 22 ++++++++++++++++++++++ Exceptions.h | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 Exceptions.cpp create mode 100644 Exceptions.h diff --git a/Exceptions.cpp b/Exceptions.cpp new file mode 100644 index 0000000..2c6fd94 --- /dev/null +++ b/Exceptions.cpp @@ -0,0 +1,22 @@ +#include"Exceptions.h" +BaseException::BaseException(const string& message) { + this->message = message; +} +string InputError::what() const { + return message; +} +InputError::InputError(const string& message) :BaseException(message) { + +} +string FileError::what() const { + return message; +} +FileError::FileError(const string& message) :BaseException(message) { + +} +string IndexError::what() const { + return message; +} +IndexError::IndexError(const string& message) :BaseException(message) { + +} diff --git a/Exceptions.h b/Exceptions.h new file mode 100644 index 0000000..a333786 --- /dev/null +++ b/Exceptions.h @@ -0,0 +1,32 @@ +#pragma once +#include +#include +#include +#include +#include +using namespace std; +class BaseException { +public: + BaseException(const string& message); + + virtual string what() const=0; + string message; +}; +class InputError :public BaseException { +public: + InputError(const string& message); + + virtual string what() const; +}; +class FileError :public BaseException { +public: + FileError(const string& message); + + virtual string what() const; +}; +class IndexError :public BaseException { +public: + IndexError(const string& message); + + virtual string what() const; +}; \ No newline at end of file