feat: corrected the try / catch (besigned method)
This commit is contained in:
parent
2b5b3b29cb
commit
ba0a5ab953
3 changed files with 21 additions and 11 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/03/17 14:19:41 by rparodi #+# #+# */
|
/* Created: 2025/03/17 14:19:41 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/03/17 22:07:57 by rparodi ### ########.fr */
|
/* Updated: 2025/03/18 09:42:55 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -80,11 +80,12 @@ std::ostream& operator<<(std::ostream& output, Form const &toPrint) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Form::beSigned(Bureaucrat &bureaucrat) {
|
void Form::beSigned(Bureaucrat &bureaucrat) {
|
||||||
if (bureaucrat.getGrade() >= this->_to_sign) {
|
if (bureaucrat.getGrade() > this->_to_sign) {
|
||||||
throw FormForSupperior();
|
throw FormForSupperior();
|
||||||
} else if (_signed) {
|
} else if (_signed == true) {
|
||||||
throw FormAlreadySigned();
|
throw FormAlreadySigned();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
std::cout << "Bureaucrat " << bureaucrat.getName() << " signs the form " << this->_name << std::endl;
|
std::cout << "Bureaucrat " << bureaucrat.getName() << " signs the form " << this->_name << std::endl;
|
||||||
this->_signed = true;
|
this->_signed = true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,8 @@ CXXFLAGS = -Werror -Wextra -Wall -std=c++98 -I./includes/
|
||||||
# Flags to have the dependences (can be removed for correction)
|
# Flags to have the dependences (can be removed for correction)
|
||||||
CXXFLAGS += -MMD
|
CXXFLAGS += -MMD
|
||||||
# Flags to have the debug (can be removed for correction)
|
# Flags to have the debug (can be removed for correction)
|
||||||
DEBUG += -g3 -fsanitize=address
|
DEBUG = -g3
|
||||||
|
DEBUG += -fsanitize=address
|
||||||
CXXFLAGS += $(DEBUG)
|
CXXFLAGS += $(DEBUG)
|
||||||
|
|
||||||
# Sources
|
# Sources
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/03/16 14:47:26 by rparodi #+# #+# */
|
/* Created: 2025/03/16 14:47:26 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/03/17 20:43:54 by rparodi ### ########.fr */
|
/* Updated: 2025/03/18 09:42:11 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -15,7 +15,6 @@
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
|
|
||||||
std::cout << YELLOW << "\t\t[ Testing with the grade 0 ]" << RESET << std::endl;
|
std::cout << YELLOW << "\t\t[ Testing with the grade 0 ]" << RESET << std::endl;
|
||||||
try {
|
try {
|
||||||
Bureaucrat b1("Roger", 0);
|
Bureaucrat b1("Roger", 0);
|
||||||
|
|
@ -62,21 +61,30 @@ int main(void) {
|
||||||
}
|
}
|
||||||
std::cout << std::endl << std::endl << b2 << std::endl << std::endl;
|
std::cout << std::endl << std::endl << b2 << std::endl << std::endl;
|
||||||
|
|
||||||
|
std::cout << b2 << std::endl;
|
||||||
try {
|
try {
|
||||||
b2.promote();
|
b2.promote();
|
||||||
} catch (std::exception & err) {
|
} catch (std::exception & err) {
|
||||||
std::cerr << RED << err.what() << RESET << std::endl;
|
std::cerr << RED << err.what() << RESET << std::endl;
|
||||||
}
|
}
|
||||||
|
std::cout << b2 << std::endl;
|
||||||
std::cout << std::endl << YELLOW << "\t\t[ Testing the overload of the '<<' operator ]" << RESET << std::endl;
|
std::cout << std::endl << YELLOW << "\t\t[ Testing the overload of the '<<' operator ]" << RESET << std::endl;
|
||||||
Form f1("Norme to cpp", 1, 1);
|
Form f1("Norme to cpp", 1, 1);
|
||||||
std::cout << f1 << std::endl;
|
std::cout << f1 << std::endl;
|
||||||
|
|
||||||
std::cout << std::endl << YELLOW << "\t\t[ Testing beSigned() methode with a new form]" << RESET << std::endl;
|
std::cout << std::endl << YELLOW << "\t\t[ Testing beSigned() methode with a new form ]" << RESET << std::endl;
|
||||||
f1.beSigned(b1);
|
try {
|
||||||
|
b2.signForm(f1);
|
||||||
|
} catch (std::exception & err) {
|
||||||
|
std::cerr << RED << err.what() << RESET << std::endl;
|
||||||
|
}
|
||||||
std::cout << f1 << std::endl;
|
std::cout << f1 << std::endl;
|
||||||
|
|
||||||
std::cout << std::endl << YELLOW << "\t\t[ Testing beSigned() methode with a signed form ]" << RESET << std::endl;
|
std::cout << std::endl << YELLOW << "\t\t[ Testing beSigned() methode with a signed form ]" << RESET << std::endl;
|
||||||
f1.beSigned(b1);
|
try {
|
||||||
|
b2.signForm(f1);
|
||||||
|
} catch (std::exception & err) {
|
||||||
|
std::cerr << RED << err.what() << RESET << std::endl;
|
||||||
|
}
|
||||||
std::cout << f1 << std::endl;
|
std::cout << f1 << std::endl;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue