@@ -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,16 @@ 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
+ " Couldn't get new temporary file name in directory" + lpPathBuffer);
56
+ }
52
57
53
58
unlink (t);
54
- if (_mkdir (t)!=0 )
55
- throw " _mkdir failed" ;
56
-
59
+ if (_mkdir (t) != 0 )
60
+ {
61
+ throw system_exceptiont (" Couldn't create temporary directory at " + t);
62
+ }
57
63
result=std::string (t);
58
64
59
65
#else
@@ -69,7 +75,7 @@ std::string get_temporary_directory(const std::string &name_template)
69
75
t.push_back (' \0 ' ); // add the zero
70
76
const char *td = mkdtemp (t.data ());
71
77
if (!td)
72
- throw " mkdtemp failed " ;
78
+ throw system_exceptiont ( " Failed to create temporary directory " ) ;
73
79
result=std::string (td);
74
80
#endif
75
81
@@ -101,11 +107,13 @@ temp_working_dirt::temp_working_dirt(const std::string &name_template):
101
107
{
102
108
old_working_directory=get_current_working_directory ();
103
109
if (chdir (path.c_str ())!=0 )
104
- CHECK_RETURN ( false );
110
+ throw system_exceptiont ( " Couldn't change directory to " + path );
105
111
}
106
112
107
- temp_working_dirt::~temp_working_dirt ()
113
+ temp_working_dirt::~temp_working_dirt () noexcept ( false )
108
114
{
115
+ // FIXME throwing from destructors is generally a bad idea
116
+ // but I can't think of anything else that'd be reasonable here?
109
117
if (chdir (old_working_directory.c_str ())!=0 )
110
- CHECK_RETURN ( false );
118
+ throw system_exceptiont ( " Couldn't change directory to " + path );
111
119
}
0 commit comments