Skip to content

Commit a77cd42

Browse files
committed
change exception texts
1 parent 7144f31 commit a77cd42

File tree

9 files changed

+61
-61
lines changed

9 files changed

+61
-61
lines changed

include/nes/named_mutex.hpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ struct named_mutex_base
7373
{
7474
handle = OpenMutexW(SYNCHRONIZE, FALSE, std::data(native_name));
7575
if(!handle)
76-
throw std::runtime_error{"Can not open named mutex. " + get_error_message()};
76+
throw std::runtime_error{"Failed to open named mutex. " + get_error_message()};
7777
}
7878
else
7979
{
80-
throw std::runtime_error{"Can not create named mutex. " + get_error_message()};
80+
throw std::runtime_error{"Failed to create named mutex. " + get_error_message()};
8181
}
8282
}
8383

@@ -94,7 +94,7 @@ struct named_mutex_base
9494
out_path.resize(required_size);
9595

9696
if(!MultiByteToWideChar(CP_UTF8, 0, std::data(path), std::size(path), std::data(out_path), std::size(out_path)))
97-
throw std::runtime_error{"Can not convert the path to wide."};
97+
throw std::runtime_error{"Failed to convert the path to wide."};
9898

9999
return out_path;
100100
}
@@ -267,19 +267,19 @@ inline mutex_base create_or_open_mutex(const std::string& name, bool recursive)
267267

268268
int shm_handle{shm_open(std::data(native_name), O_RDWR | O_CREAT, 0660)};
269269
if(shm_handle == -1)
270-
throw std::runtime_error{"Can not allocate space for named mutex. " + std::string{strerror(errno)}};
270+
throw std::runtime_error{"Failed to allocate space for named mutex. " + std::string{strerror(errno)}};
271271

272272
if(ftruncate(shm_handle, sizeof(mutex_data)) == -1)
273273
{
274274
close(shm_handle);
275-
throw std::runtime_error{"Can not truncate shared memory for named mutex. " + std::string{strerror(errno)}};
275+
throw std::runtime_error{"Failed to truncate shared memory for named mutex. " + std::string{strerror(errno)}};
276276
}
277277

278278
auto* ptr{reinterpret_cast<mutex_data*>(mmap(nullptr, sizeof(mutex_data), PROT_READ | PROT_WRITE, MAP_SHARED, shm_handle, 0))};
279279
if(ptr == MAP_FAILED)
280280
{
281281
close(shm_handle);
282-
throw std::runtime_error{"Can not map shared memory for named mutex. " + std::string{strerror(errno)}};
282+
throw std::runtime_error{"Failed to map shared memory for named mutex. " + std::string{strerror(errno)}};
283283
}
284284

285285
if(!ptr->opened)
@@ -296,17 +296,17 @@ inline mutex_base create_or_open_mutex(const std::string& name, bool recursive)
296296
};
297297

298298
if(auto error = pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED); error != 0)
299-
clean_and_throw("Can not set process shared attribute of mutex. ", error);
299+
clean_and_throw("Failed to set process shared attribute of mutex. ", error);
300300

301301
if(auto error = pthread_mutexattr_setrobust(&attr, PTHREAD_MUTEX_ROBUST); error != 0)
302-
clean_and_throw("Can not set robust attribute of mutex. ", error);
302+
clean_and_throw("Failed to set robust attribute of mutex. ", error);
303303

304304
if(recursive)
305305
if(auto error = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); error != 0)
306-
clean_and_throw("Can not set recursive attribute of mutex. ", error);
306+
clean_and_throw("Failed to set recursive attribute of mutex. ", error);
307307

308308
if(auto error = pthread_mutex_init(&ptr->mutex, &attr); error != 0)
309-
clean_and_throw("Can not init mutex. ", error);
309+
clean_and_throw("Failed to init mutex. ", error);
310310

311311
pthread_mutexattr_destroy(&attr);
312312

@@ -330,7 +330,7 @@ inline void lock_mutex(mutex_base& mutex)
330330
if(error == EOWNERDEAD)
331331
pthread_mutex_consistent(&mutex.data->mutex);
332332
else if(error != 0)
333-
throw std::runtime_error{"Can not lock mutex. " + std::string{strerror(error)}};
333+
throw std::runtime_error{"Failed to lock mutex. " + std::string{strerror(error)}};
334334
}
335335

336336
inline bool try_lock_mutex(mutex_base& mutex)

include/nes/named_semaphore.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ class named_semaphore
7272
{
7373
m_handle = OpenSemaphoreW(SYNCHRONIZE, FALSE, std::data(native_name));
7474
if(!m_handle)
75-
throw std::runtime_error{"Can not open semaphore. " + get_error_message()};
75+
throw std::runtime_error{"Failed to open semaphore. " + get_error_message()};
7676
}
7777
else
7878
{
79-
throw std::runtime_error{"Can not create semaphore. " + get_error_message()};
79+
throw std::runtime_error{"Failed to create semaphore. " + get_error_message()};
8080
}
8181
}
8282
}
@@ -124,7 +124,7 @@ class named_semaphore
124124
out_path.resize(required_size);
125125

126126
if(!MultiByteToWideChar(CP_UTF8, 0, std::data(path), std::size(path), std::data(out_path), std::size(out_path)))
127-
throw std::runtime_error{"Can not convert the path to wide."};
127+
throw std::runtime_error{"Failed to convert the path to wide."};
128128

129129
return out_path;
130130
}
@@ -164,11 +164,11 @@ class timed_named_semaphore
164164
{
165165
m_handle = OpenSemaphoreW(SYNCHRONIZE, FALSE, std::data(native_name));
166166
if(!m_handle)
167-
throw std::runtime_error{"Can not open semaphore. " + get_error_message()};
167+
throw std::runtime_error{"Failed to open semaphore. " + get_error_message()};
168168
}
169169
else
170170
{
171-
throw std::runtime_error{"Can not create semaphore. " + get_error_message()};
171+
throw std::runtime_error{"Failed to create semaphore. " + get_error_message()};
172172
}
173173
}
174174
}
@@ -232,7 +232,7 @@ class timed_named_semaphore
232232
out_path.resize(required_size);
233233

234234
if(!MultiByteToWideChar(CP_UTF8, 0, std::data(path), std::size(path), std::data(out_path), std::size(out_path)))
235-
throw std::runtime_error{"Can not convert the path to wide."};
235+
throw std::runtime_error{"Failed to convert the path to wide."};
236236

237237
return out_path;
238238
}
@@ -276,7 +276,7 @@ class named_semaphore
276276

277277
m_handle = sem_open(std::data(native_name), O_CREAT, 0660, initial_count);
278278
if(m_handle == SEM_FAILED)
279-
throw std::runtime_error{"Can not create semaphore. " + std::string{strerror(errno)}};
279+
throw std::runtime_error{"Failed to create semaphore. " + std::string{strerror(errno)}};
280280
}
281281

282282
~named_semaphore()
@@ -327,7 +327,7 @@ class timed_named_semaphore
327327

328328
m_handle = sem_open(std::data(native_name), O_CREAT, 0660, initial_count);
329329
if(m_handle == SEM_FAILED)
330-
throw std::runtime_error{"Can not create semaphore. " + std::string{strerror(errno)}};
330+
throw std::runtime_error{"Failed to create semaphore. " + std::string{strerror(errno)}};
331331
}
332332

333333
~timed_named_semaphore()

include/nes/pipe.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ class basic_pipe_streambuf : public std::basic_streambuf<CharT, Traits>
268268
out_path.resize(required_size);
269269

270270
if(!MultiByteToWideChar(CP_UTF8, 0, std::data(path), std::size(path), std::data(out_path), std::size(out_path)))
271-
throw std::runtime_error{"Can not convert the path to wide."};
271+
throw std::runtime_error{"Failed to convert the path to wide."};
272272

273273
return out_path;
274274
}
@@ -449,7 +449,7 @@ std::pair<basic_pipe_istream<CharT, Traits>, basic_pipe_ostream<CharT, Traits>>
449449
HANDLE output{};
450450

451451
if(!CreatePipe(&input, &output, nullptr, 0))
452-
throw std::runtime_error{"Can not create pipe"};
452+
throw std::runtime_error{"Failed to create pipe"};
453453

454454
return std::make_pair(basic_pipe_istream<CharT, Traits>{basic_pipe_streambuf<CharT, Traits>{input, std::ios_base::in}},
455455
basic_pipe_ostream<CharT, Traits>{basic_pipe_streambuf<CharT, Traits>{output, std::ios_base::out}});
@@ -824,7 +824,7 @@ std::pair<basic_pipe_istream<CharT, Traits>, basic_pipe_ostream<CharT, Traits>>
824824
int fd[2];
825825

826826
if(pipe(fd))
827-
throw std::runtime_error{"Can not create pipe"};
827+
throw std::runtime_error{"Failed to create pipe"};
828828

829829
return std::make_pair(basic_pipe_istream<CharT, Traits>{basic_pipe_streambuf<CharT, Traits>{fd[0], std::ios_base::in}},
830830
basic_pipe_ostream<CharT, Traits>{basic_pipe_streambuf<CharT, Traits>{fd[1], std::ios_base::out}});

include/nes/process.hpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -249,15 +249,15 @@ class process
249249

250250
if(static_cast<bool>(options & process_options::grab_stdin))
251251
if(!CreatePipe(&stdin_rd, &stdin_wr, &security_attributes, 0) || !SetHandleInformation(stdin_wr, HANDLE_FLAG_INHERIT, 0))
252-
throw std::runtime_error{"Can not create stdin pipe. " + get_error_message()};
252+
throw std::runtime_error{"Failed to create stdin pipe. " + get_error_message()};
253253

254254
if(static_cast<bool>(options & process_options::grab_stdout))
255255
if(!CreatePipe(&stdout_rd, &stdout_wr, &security_attributes, 0) || !SetHandleInformation(stdout_rd, HANDLE_FLAG_INHERIT, 0))
256-
throw std::runtime_error{"Can not create stdout pipe. " + get_error_message()};
256+
throw std::runtime_error{"Failed to create stdout pipe. " + get_error_message()};
257257

258258
if(static_cast<bool>(options & process_options::grab_stderr))
259259
if(!CreatePipe(&stderr_rd, &stderr_wr, &security_attributes, 0) || !SetHandleInformation(stderr_rd, HANDLE_FLAG_INHERIT, 0))
260-
throw std::runtime_error{"Can not create stderr pipe. " + get_error_message()};
260+
throw std::runtime_error{"Failed to create stderr pipe. " + get_error_message()};
261261
#endif
262262

263263
args.insert(std::begin(args), path);
@@ -326,7 +326,7 @@ class process
326326

327327
PROCESS_INFORMATION process_info{};
328328
if(!CreateProcessW(std::data(native_path), null_or_data(args_str), nullptr, nullptr, TRUE, 0, nullptr, null_or_data(native_working_directory), &startup_info, &process_info))
329-
throw std::runtime_error{"Can not create process. " + get_error_message()};
329+
throw std::runtime_error{"Failed to create process. " + get_error_message()};
330330

331331
m_id = static_cast<id>(process_info.dwProcessId);
332332
m_handle = process_info.hProcess;
@@ -401,10 +401,10 @@ class process
401401
assert(joinable() && "nes::process::join() called with joinable() returning false.");
402402

403403
if(WaitForSingleObject(m_handle, INFINITE))
404-
throw std::runtime_error{"Can not join the process. " + get_error_message()};
404+
throw std::runtime_error{"Failed to join the process. " + get_error_message()};
405405

406406
if(!GetExitCodeProcess(m_handle, reinterpret_cast<DWORD*>(&m_return_code)))
407-
throw std::runtime_error{"Can not get the return code of the process. " + get_error_message()};
407+
throw std::runtime_error{"Failed to get the return code of the process. " + get_error_message()};
408408

409409
close_process();
410410
}
@@ -421,7 +421,7 @@ class process
421421

422422
DWORD result = WaitForSingleObject(m_handle, 0);
423423
if(result == WAIT_FAILED)
424-
throw std::runtime_error{"Can not get the state of the process. " + get_error_message()};
424+
throw std::runtime_error{"Failed to get the state of the process. " + get_error_message()};
425425

426426
return result == WAIT_TIMEOUT;
427427
}
@@ -490,7 +490,7 @@ class process
490490
out_path.resize(required_size);
491491

492492
if(!MultiByteToWideChar(CP_UTF8, 0, std::data(path), std::size(path), std::data(out_path), std::size(out_path)))
493-
throw std::runtime_error{"Can not convert the path to wide."};
493+
throw std::runtime_error{"Failed to convert the path to wide."};
494494

495495
return out_path;
496496
}
@@ -561,7 +561,7 @@ inline std::string working_directory()
561561
path.resize(required_size);
562562

563563
if(!WideCharToMultiByte(CP_UTF8, 0, std::data(native_path), std::size(native_path), std::data(path), std::size(path), nullptr, nullptr))
564-
throw std::runtime_error{"Can not convert the path to UTF-8."};
564+
throw std::runtime_error{"Failed to convert the path to UTF-8."};
565565

566566
return path;
567567
}
@@ -573,7 +573,7 @@ inline bool change_working_directory(const std::string& path)
573573
native_path.resize(required_size);
574574

575575
if(!MultiByteToWideChar(CP_UTF8, 0, std::data(path), std::size(path), std::data(native_path), std::size(native_path)))
576-
throw std::runtime_error{"Can not convert the path to wide."};
576+
throw std::runtime_error{"Failed to convert the path to wide."};
577577

578578
return SetCurrentDirectoryW(std::data(native_path));
579579
}
@@ -799,13 +799,13 @@ class process
799799
impl::auto_handle stderr_fd[2]{};
800800

801801
if(static_cast<bool>(options & process_options::grab_stdin) && pipe(reinterpret_cast<int*>(stdin_fd)))
802-
throw std::runtime_error{"Can not create stdin pipe. " + std::string{strerror(errno)}};
802+
throw std::runtime_error{"Failed to create stdin pipe. " + std::string{strerror(errno)}};
803803

804804
if(static_cast<bool>(options & process_options::grab_stdout) && pipe(reinterpret_cast<int*>(stdout_fd)))
805-
throw std::runtime_error{"Can not create stdout pipe. " + std::string{strerror(errno)}};
805+
throw std::runtime_error{"Failed to create stdout pipe. " + std::string{strerror(errno)}};
806806

807807
if(static_cast<bool>(options & process_options::grab_stderr) && pipe(reinterpret_cast<int*>(stderr_fd)))
808-
throw std::runtime_error{"Can not create stderr pipe. " + std::string{strerror(errno)}};
808+
throw std::runtime_error{"Failed to create stderr pipe. " + std::string{strerror(errno)}};
809809

810810
const bool standard_streams{static_cast<bool>(options & process_options::grab_stdin) || static_cast<bool>(options & process_options::grab_stdout) || static_cast<bool>(options & process_options::grab_stderr)};
811811
#else
@@ -819,7 +819,7 @@ class process
819819

820820
if(id < 0)
821821
{
822-
throw std::runtime_error{"Can not create process. " + std::string{strerror(errno)}};
822+
throw std::runtime_error{"Failed to create process. " + std::string{strerror(errno)}};
823823
}
824824
else if(id == 0)
825825
{
@@ -833,7 +833,7 @@ class process
833833

834834
if(id < 0)
835835
{
836-
throw std::runtime_error{"Can not create process. " + std::string{strerror(errno)}};
836+
throw std::runtime_error{"Failed to create process. " + std::string{strerror(errno)}};
837837
}
838838
else if(id == 0)
839839
{
@@ -920,7 +920,7 @@ class process
920920

921921
int return_code{};
922922
if(waitpid(m_id, &return_code, 0) == -1)
923-
throw std::runtime_error{"Can not join the process. " + std::string{strerror(errno)}};
923+
throw std::runtime_error{"Failed to join the process. " + std::string{strerror(errno)}};
924924

925925
m_id = -1;
926926
m_return_code = WEXITSTATUS(return_code);
@@ -1016,7 +1016,7 @@ inline std::string working_directory()
10161016
if(errno == ERANGE)
10171017
path.resize(std::size(path) * 2);
10181018
else
1019-
throw std::runtime_error{"Can not get the current working directory. " + std::string{strerror(errno)}};
1019+
throw std::runtime_error{"Failed to get the current working directory. " + std::string{strerror(errno)}};
10201020
}
10211021

10221022
path.resize(path.find_first_of('\0'));

include/nes/semaphore.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class semaphore
6363
{
6464
m_handle = CreateSemaphoreW(nullptr, static_cast<LONG>(initial_count), std::numeric_limits<LONG>::max(), nullptr);
6565
if(!m_handle)
66-
throw std::runtime_error{"Can not create semaphore. " + get_error_message()};
66+
throw std::runtime_error{"Failed to create semaphore. " + get_error_message()};
6767
}
6868

6969
~semaphore()
@@ -128,7 +128,7 @@ class timed_semaphore
128128
{
129129
m_handle = CreateSemaphoreW(nullptr, static_cast<LONG>(initial_count), std::numeric_limits<LONG>::max(), nullptr);
130130
if(!m_handle)
131-
throw std::runtime_error{"Can not create semaphore. " + get_error_message()};
131+
throw std::runtime_error{"Failed to create semaphore. " + get_error_message()};
132132
}
133133

134134
~timed_semaphore()
@@ -214,7 +214,7 @@ class semaphore
214214
explicit semaphore(std::size_t initial_count = 0)
215215
{
216216
if(sem_init(m_handle.get(), 0, initial_count) != 0)
217-
throw std::runtime_error{"Can not create semaphore. " + std::string{strerror(errno)}};
217+
throw std::runtime_error{"Failed to create semaphore. " + std::string{strerror(errno)}};
218218
}
219219

220220
~semaphore()
@@ -262,7 +262,7 @@ class timed_semaphore
262262
explicit timed_semaphore(std::size_t initial_count = 0)
263263
{
264264
if(sem_init(m_handle.get(), 0, initial_count) != 0)
265-
throw std::runtime_error{"Can not create timed_semaphore. " + std::string{strerror(errno)}};
265+
throw std::runtime_error{"Failed to create timed_semaphore. " + std::string{strerror(errno)}};
266266
}
267267

268268
~timed_semaphore()

include/nes/shared_library.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class shared_library
6464
{
6565
m_handle = GetModuleHandleW(nullptr);
6666
if(!m_handle)
67-
throw std::runtime_error{"Can not load current binary file. " + get_error_message()};
67+
throw std::runtime_error{"Failed to load current binary file. " + get_error_message()};
6868
}
6969

7070
explicit shared_library(const std::string& path)
@@ -73,7 +73,7 @@ class shared_library
7373

7474
m_handle = LoadLibraryW(to_wide(path).c_str());
7575
if(!m_handle)
76-
throw std::runtime_error{"Can not load binary file \"" + path + "\". " + get_error_message()};
76+
throw std::runtime_error{"Failed to load binary file \"" + path + "\". " + get_error_message()};
7777
m_need_free = true;
7878
}
7979

@@ -131,7 +131,7 @@ class shared_library
131131
out_path.resize(required_size);
132132

133133
if(!MultiByteToWideChar(CP_UTF8, 0, std::data(path), std::size(path), std::data(out_path), std::size(out_path)))
134-
throw std::runtime_error{"Can not convert the path to wide."};
134+
throw std::runtime_error{"Failed to convert the path to wide."};
135135

136136
return out_path;
137137
}
@@ -176,7 +176,7 @@ class shared_library
176176
{
177177
m_handle = dlopen(nullptr, RTLD_NOW);
178178
if(!m_handle)
179-
throw std::runtime_error{"Can not load current binary file. " + std::string{dlerror()}};
179+
throw std::runtime_error{"Failed to load current binary file. " + std::string{dlerror()}};
180180
}
181181

182182
explicit shared_library(const std::string& path)
@@ -185,7 +185,7 @@ class shared_library
185185

186186
m_handle = dlopen(std::data(path), RTLD_NOW);
187187
if(!m_handle)
188-
throw std::runtime_error{"Can not load binary file \"" + path + "\". " + std::string{dlerror()}};
188+
throw std::runtime_error{"Failed to load binary file \"" + path + "\". " + std::string{dlerror()}};
189189
}
190190

191191
~shared_library()

0 commit comments

Comments
 (0)