@@ -26,7 +26,7 @@ Author: CM Wintersteiger
26
26
#include < unistd.h>
27
27
#endif
28
28
29
- #include " invariant .h"
29
+ #include " exception_utils .h"
30
30
#include " file_util.h"
31
31
32
32
std::string get_temporary_directory (const std::string &name_template)
@@ -39,7 +39,9 @@ std::string get_temporary_directory(const std::string &name_template)
39
39
DWORD dwRetVal = GetTempPathA (dwBufSize, lpPathBuffer);
40
40
41
41
if (dwRetVal > dwBufSize || (dwRetVal == 0 ))
42
- throw " GetTempPath failed" ; // NOLINT(readability/throw)
42
+ {
43
+ throw system_exceptiont (" Couldn't get temporary path" );
44
+ }
43
45
44
46
// GetTempFileNameA produces <path>\<pre><uuuu>.TMP
45
47
// where <pre> = "TLO"
@@ -48,12 +50,18 @@ std::string get_temporary_directory(const std::string &name_template)
48
50
char t[MAX_PATH];
49
51
UINT uRetVal=GetTempFileNameA (lpPathBuffer, " TLO" , 0 , t);
50
52
if (uRetVal == 0 )
51
- throw " GetTempFileName failed" ; // NOLINT(readability/throw)
53
+ {
54
+ throw system_exceptiont (
55
+ std::string (" Couldn't get new temporary file name in directory" ) +
56
+ lpPathBuffer);
57
+ }
52
58
53
59
unlink (t);
54
- if (_mkdir (t)!=0 )
55
- throw " _mkdir failed" ;
56
-
60
+ if (_mkdir (t) != 0 )
61
+ {
62
+ throw system_exceptiont (
63
+ std::string (" Couldn't create temporary directory at " ) + t);
64
+ }
57
65
result=std::string (t);
58
66
59
67
#else
@@ -69,7 +77,7 @@ std::string get_temporary_directory(const std::string &name_template)
69
77
t.push_back (' \0 ' ); // add the zero
70
78
const char *td = mkdtemp (t.data ());
71
79
if (!td)
72
- throw " mkdtemp failed " ;
80
+ throw system_exceptiont ( " Failed to create temporary directory " ) ;
73
81
result=std::string (td);
74
82
#endif
75
83
@@ -101,11 +109,13 @@ temp_working_dirt::temp_working_dirt(const std::string &name_template):
101
109
{
102
110
old_working_directory=get_current_working_directory ();
103
111
if (chdir (path.c_str ())!=0 )
104
- CHECK_RETURN ( false );
112
+ throw system_exceptiont ( " Couldn't change directory to " + path );
105
113
}
106
114
107
- temp_working_dirt::~temp_working_dirt ()
115
+ temp_working_dirt::~temp_working_dirt () noexcept ( false )
108
116
{
117
+ // FIXME throwing from destructors is generally a bad idea
118
+ // but I can't think of anything else that'd be reasonable here?
109
119
if (chdir (old_working_directory.c_str ())!=0 )
110
- CHECK_RETURN ( false );
120
+ throw system_exceptiont ( " Couldn't change directory to " + path );
111
121
}
0 commit comments