Pol  Revision:4b29d2b
iohelp.cpp
Go to the documentation of this file.
1 
7 #include "iohelp.h"
8 
9 #include <stdexcept>
10 
11 // note this is only useful if ofs.exceptions( std::ios_base::failbit | std::ios_base::badbit ) is
12 // called
13 namespace Pol
14 {
15 namespace Clib
16 {
17 void open_file( std::fstream& ofs, std::string& filename, std::ios::openmode mode )
18 {
19  try
20  {
21  ofs.open( filename.c_str(), mode );
22  }
23  catch ( std::exception& ex )
24  {
25  std::string message = "Error opening file " + filename + ": " + ex.what();
26  throw std::runtime_error( message );
27  }
28 }
29 void open_file( std::ofstream& ofs, std::string& filename, std::ios::openmode mode )
30 {
31  try
32  {
33  ofs.open( filename.c_str(), mode );
34  }
35  catch ( std::exception& ex )
36  {
37  std::string message = "Error opening file " + filename + ": " + ex.what();
38  throw std::runtime_error( message );
39  }
40 }
41 
42 void open_file( std::ifstream& ifs, std::string& filename, std::ios::openmode mode )
43 {
44  try
45  {
46  ifs.open( filename.c_str(), mode );
47  }
48  catch ( std::exception& ex )
49  {
50  std::string message = "Error opening file " + filename + ": " + ex.what();
51  throw std::runtime_error( message );
52  }
53 }
54 }
55 }
void open_file(std::fstream &ofs, std::string &filename, std::ios::openmode mode)
Definition: iohelp.cpp:17
Definition: berror.cpp:12