add exception class

This commit is contained in:
arthur.jamet
2021-05-23 17:43:34 +02:00
parent 57ebac7813
commit 1f7b19b345
6 changed files with 95 additions and 7 deletions
+5 -3
View File
@@ -51,6 +51,7 @@ set(HEADERS
sources/Drawables/3D/Ray.hpp
sources/Drawables/3D/Sphere.hpp
sources/Drawables/3D/Triangle.hpp
sources/Exceptions/RayError.hpp
sources/Model/Model.hpp
sources/Model/ModelAnimation.hpp
sources/Model/ModelAnimations.hpp
@@ -62,9 +63,6 @@ set(SRC
sources/Color.cpp
sources/Font.cpp
sources/Window.cpp
sources/Model/Model.cpp
sources/Model/ModelAnimation.cpp
sources/Model/ModelAnimations.cpp
sources/Audio/Music.cpp
sources/Audio/Sound.cpp
sources/Camera/Camera2D.cpp
@@ -92,6 +90,10 @@ set(SRC
sources/Drawables/ADrawable3D.cpp
sources/Drawables/Image.cpp
sources/Drawables/Texture.cpp
sources/Exceptions/RayError.cpp
sources/Model/Model.cpp
sources/Model/ModelAnimation.cpp
sources/Model/ModelAnimations.cpp
sources/Vector/Vector2.cpp
sources/Vector/Vector3.cpp
)
+2 -2
View File
@@ -6,7 +6,7 @@
*/
#include "Drawables/2D/Triangle.hpp"
#include <exception>
#include "Exceptions/RayError.hpp"
RAY::Drawables::Drawables2D::Triangle::Triangle(const Vector2 &positionA, const Vector2 &positionB, const Vector2 &positionC, const Color &color):
ADrawable2D(positionA, color), _posB(positionB), _posC(positionC)
@@ -54,6 +54,6 @@ void RAY::Drawables::Drawables2D::Triangle::drawOn(RAY::Window &)
void RAY::Drawables::Drawables2D::Triangle::drawOn(RAY::Image &)
{
throw std::exception();
throw RAY::Exception::NotSupportedError("An triangle cannot be drawn on an image");
}
+23
View File
@@ -0,0 +1,23 @@
/*
** EPITECH PROJECT, 2021
** Bomberman
** File description:
** RayError
*/
#include "RayError.hpp"
RAY::Exception::RayError::RayError(const std::string &expectionMessage):
runtime_error(expectionMessage)
{
}
RAY::Exception::NotSupportedError::NotSupportedError(const std::string &expectionMessage):
RayError(expectionMessage)
{
}
RAY::Exception::NotCompatibleError::NotCompatibleError(const std::string &expectionMessage):
RayError(expectionMessage)
{
}
+63
View File
@@ -0,0 +1,63 @@
/*
** EPITECH PROJECT, 2021
** Bomberman
** File description:
** RayError
*/
#ifndef RAYERROR_HPP_
#define RAYERROR_HPP_
#include <stdexcept>
namespace RAY::Exception {
//! @brief base exception class for RAY lib
class RayError: public std::runtime_error {
public:
//! @brief Create a new RAY exception
RayError(const std::string &what);
//! @brief A default destructor
~RayError() = default;
//! @brief A RAY exception is copy constructable
RayError(const RayError &) = default;
//! @brief A default assignment operator
RayError &operator=(const RayError &) = default;
};
//! @brief exception used when an incompatibility occurs
class NotCompatibleError: public RayError {
public:
//! @brief Create a new exception instance
NotCompatibleError(const std::string &what);
//! @brief A default destructor
~NotCompatibleError() = default;
//! @brief An exception is copy constructable
NotCompatibleError(const NotCompatibleError &) = default;
//! @brief A default assignment operator
NotCompatibleError &operator=(const NotCompatibleError &) = default;
};
//! @brief exception used when an non-supported operation is done
class NotSupportedError: public RayError {
public:
//! @brief Create a new exception instance
NotSupportedError(const std::string &what = "This operation is currently not supported");
//! @brief A default destructor
~NotSupportedError() = default;
//! @brief An exception is copy constructable
NotSupportedError(const NotSupportedError &) = default;
//! @brief A default assignment operator
NotSupportedError &operator=(const NotSupportedError &) = default;
};
}
#endif /* !RAYERROR_HPP_ */
+2 -1
View File
@@ -6,6 +6,7 @@
*/
#include "Model/Model.hpp"
#include "Exceptions/RayError.hpp"
RAY::Model::Model(const std::string &filename):
_model(LoadModel(filename.c_str()))
@@ -49,7 +50,7 @@ bool RAY::Model::unloadKeepMeshes()
bool RAY::Model::setAnimation(const RAY::ModelAnimation &animation)
{
if (!IsModelAnimationValid(this->_model, animation))
return false;
throw RAY::Exception::NotCompatibleError("The animation is not compatible with the model");
UpdateModelAnimation(this->_model, animation, animation.getFrameCounter());
return true;
}
-1
View File
@@ -52,7 +52,6 @@ namespace RAY {
bool unloadKeepMeshes();
//! @brief Update model animation pose
//! @return false if animation is not compatible
bool setAnimation(const RAY::ModelAnimation &animation);
//! @brief Sets a texture to the Nth material