comparison Core/Toolbox.cpp @ 1582:bd1889029cbb

encoding of exceptions
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 25 Aug 2015 17:39:38 +0200
parents 4b23310eb7e8
children b5bc87a7212d
comparison
equal deleted inserted replaced
1581:357c4bb15701 1582:bd1889029cbb
253 void Toolbox::RemoveFile(const std::string& path) 253 void Toolbox::RemoveFile(const std::string& path)
254 { 254 {
255 if (boost::filesystem::exists(path)) 255 if (boost::filesystem::exists(path))
256 { 256 {
257 if (boost::filesystem::is_regular_file(path)) 257 if (boost::filesystem::is_regular_file(path))
258 {
258 boost::filesystem::remove(path); 259 boost::filesystem::remove(path);
260 }
259 else 261 else
260 throw OrthancException("The path is not a regular file: " + path); 262 {
263 throw OrthancException(ErrorCode_RegularFileExpected);
264 }
261 } 265 }
262 } 266 }
263 267
264 268
265 269
528 { 532 {
529 std::vector<char> buffer(PATH_MAX + 1); 533 std::vector<char> buffer(PATH_MAX + 1);
530 ssize_t bytes = readlink("/proc/self/exe", &buffer[0], buffer.size() - 1); 534 ssize_t bytes = readlink("/proc/self/exe", &buffer[0], buffer.size() - 1);
531 if (bytes == 0) 535 if (bytes == 0)
532 { 536 {
533 throw OrthancException("Unable to get the path to the executable"); 537 throw OrthancException(ErrorCode_PathToExecutable);
534 } 538 }
535 539
536 return std::string(&buffer[0]); 540 return std::string(&buffer[0]);
537 } 541 }
538 542
1017 { 1021 {
1018 if (boost::filesystem::exists(path)) 1022 if (boost::filesystem::exists(path))
1019 { 1023 {
1020 if (!boost::filesystem::is_directory(path)) 1024 if (!boost::filesystem::is_directory(path))
1021 { 1025 {
1022 throw OrthancException("Cannot create the directory over an existing file: " + path); 1026 throw OrthancException(ErrorCode_DirectoryOverFile);
1023 } 1027 }
1024 } 1028 }
1025 else 1029 else
1026 { 1030 {
1027 if (!boost::filesystem::create_directories(path)) 1031 if (!boost::filesystem::create_directories(path))
1028 { 1032 {
1029 throw OrthancException("Unable to create the directory: " + path); 1033 throw OrthancException(ErrorCode_MakeDirectory);
1030 } 1034 }
1031 } 1035 }
1032 } 1036 }
1033 1037
1034 1038