Added error handling
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user