Skip to content

Commit

Permalink
ADD - exception
Browse files Browse the repository at this point in the history
  • Loading branch information
Bygius committed Jun 13, 2020
1 parent ee7bf4e commit ca65af4
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 1 deletion.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ add_subdirectory(GameScene)
add_subdirectory(Menu)
add_subdirectory(Settings)
add_subdirectory(Storage)
add_subdirectory(Exception)

# define sources to use
set(SRCS Application/main.cpp CPack/win32.rc)
Expand Down
17 changes: 17 additions & 0 deletions Exception/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
cmake_minimum_required(VERSION 3.11)

# project name
project(exception)

# c++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED on)

# define sources to use
set(SRCS Error.hpp Error.cpp)

# define the binary output
add_library(${PROJECT_NAME} ${SRCS})

# expose the headers
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
23 changes: 23 additions & 0 deletions Exception/Error.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
** EPITECH PROJECT, 2020
** epitech-indiestudio
** File description:
** Error
*/

#include "Error.hpp"

Error::Error(const std::string &msg = "")
{
_error_msg = msg;
}

const char *Error::what() const throw()
{
return _error_msg.c_str();
}

StorageError::StorageError(const std::string &msg = "") : Error(msg)
{

}
30 changes: 30 additions & 0 deletions Exception/Error.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
** EPITECH PROJECT, 2020
** epitech-indiestudio
** File description:
** Exception
*/

#ifndef EXCEPTION_HPP_
#define EXCEPTION_HPP_

#include <exception>
#include <string>

class Error : public std::exception {
public:
Error(const std::string &msg);
virtual ~Error() throw() {}
virtual const char *what() const throw();
protected:
std::string _error_msg;
};

class StorageError : public Error
{
public:
StorageError(const std::string &msg);
virtual ~StorageError() throw(){}
};

#endif /* !EXCEPTION_HPP_ */
3 changes: 3 additions & 0 deletions Storage/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ add_library(${PROJECT_NAME} ${SRCS})
# expose the headers
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

# define the external libraries to use
target_link_libraries(${PROJECT_NAME} exception)

4 changes: 3 additions & 1 deletion Storage/Storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

#include "Storage.hpp"
#include "Error.hpp"
#include <iostream>

Storage::Storage() {
Expand All @@ -14,7 +15,8 @@ Storage::Storage() {
if (BasePath.empty()) {
std::cerr << "Storage: " << "ERROR! Could not find your operating system" << std::endl;
std::cerr << "Storage: " << "ERROR! Can't recover, Aborting now" << std::endl;
abort();
throw StorageError("Could not find your operating system");
//abort();
}

if (!fs::exists(BasePath)) {
Expand Down

0 comments on commit ca65af4

Please sign in to comment.