mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-05-29 17:02:11 +00:00
add exception class
This commit is contained in:
@@ -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
|
||||
)
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
}
|
||||
@@ -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_ */
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user