Added error handling

This commit is contained in:
2025-08-29 00:02:45 +02:00
parent f93c463647
commit df4e7777de
17 changed files with 144 additions and 17 deletions

View File

@ -4,6 +4,7 @@
#include <optional>
#include <fstream>
#include <stdexcept>
#include "error.hpp"
// Razlicite pomocne funkcije za tekstove
namespace fsh::util {
@ -25,19 +26,19 @@ namespace fsh::util {
static inline std::ifstream input(const std::string& x) {
std::ifstream in(x, std::ios::in);
if (!in) { throw std::runtime_error("Can't open file"); }
if (!in) { throw FileOpenError(); }
return in;
}
static inline std::ofstream output(const std::string& x) {
std::ofstream out(x, std::ios::out);
if (!out.is_open()) { throw std::runtime_error("Can't open file"); }
if (!out.is_open()) { throw FileOpenError(); }
return out;
}
static inline std::ofstream output_append(const std::string& x) {
std::ofstream out(x, std::ios::app | std::ios::out);
if (!out.is_open()) { throw std::runtime_error("Can't open file"); }
if (!out.is_open()) { throw FileOpenError(); }
return out;
}