From 452e6bfa7bb4bca75dc4659bf9d707101b411977 Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Tue, 17 Nov 2020 19:02:35 +0100 Subject: Added cpp05/ex02 main, Added cpp05/ex03 --- cpp05/ex02/Form.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'cpp05/ex02/Form.cpp') diff --git a/cpp05/ex02/Form.cpp b/cpp05/ex02/Form.cpp index 8f3afc0..9208f7f 100644 --- a/cpp05/ex02/Form.cpp +++ b/cpp05/ex02/Form.cpp @@ -6,7 +6,7 @@ /* By: charles +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/14 19:26:39 by charles #+# #+# */ -/* Updated: 2020/11/17 13:35:10 by cacharle ### ########.fr */ +/* Updated: 2020/11/17 17:09:53 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -53,7 +53,9 @@ void Form::beSigned(Bureaucrat const& b) void Form::execute(Bureaucrat const& executor) const { - if (executor.getGrade() <= m_gradeExecute && m_signed) + if (!m_signed) + throw Form::NoSignatureException(); + if (executor.getGrade() <= m_gradeExecute) executeUnsafe(); else throw Form::GradeTooLowException(); @@ -126,3 +128,23 @@ Form::GradeTooLowException::operator=(GradeTooLowException const& other) Form::GradeTooLowException::~GradeTooLowException() throw() {} char const* Form::GradeTooLowException::what() const throw() { return "Grade is too low for form"; } + +/////////////////////////////////////////////////////////////////////////////// +// Exception signature +/////////////////////////////////////////////////////////////////////////////// + +Form::NoSignatureException::NoSignatureException() : std::exception() {} + +Form::NoSignatureException::NoSignatureException(NoSignatureException const& other) + : std::exception(other) {} + +Form::NoSignatureException& +Form::NoSignatureException::operator=(NoSignatureException const& other) +{ + std::exception::operator=(other); + return *this; +} + +Form::NoSignatureException::~NoSignatureException() throw() {} + +char const* Form::NoSignatureException::what() const throw() { return "No signature"; } -- cgit