polserver/pol-core/clib/iohelp.cpp

56 lines
1.1 KiB
C++
Raw Permalink Normal View History

/** @file
*
* @par History
*/
2016-02-11 22:54:43 +01:00
#include "iohelp.h"
#include <stdexcept>
// note this is only useful if ofs.exceptions( std::ios_base::failbit | std::ios_base::badbit ) is
// called
namespace Pol
{
namespace Clib
{
void open_file( std::fstream& ofs, std::string& filename, std::ios::openmode mode )
{
try
{
ofs.open( filename.c_str(), mode );
}
catch ( std::exception& ex )
{
std::string message = "Error opening file " + filename + ": " + ex.what();
throw std::runtime_error( message );
}
}
void open_file( std::ofstream& ofs, std::string& filename, std::ios::openmode mode )
{
try
{
ofs.open( filename.c_str(), mode );
}
catch ( std::exception& ex )
{
std::string message = "Error opening file " + filename + ": " + ex.what();
throw std::runtime_error( message );
}
}
2016-02-11 22:54:43 +01:00
void open_file( std::ifstream& ifs, std::string& filename, std::ios::openmode mode )
{
try
{
ifs.open( filename.c_str(), mode );
}
catch ( std::exception& ex )
{
std::string message = "Error opening file " + filename + ": " + ex.what();
throw std::runtime_error( message );
2016-02-11 22:54:43 +01:00
}
}
}
}