comparison Core/FileStorage/FilesystemStorage.cpp @ 1582:bd1889029cbb

encoding of exceptions
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 25 Aug 2015 17:39:38 +0200
parents 23083810d543
children b1291df2f780
comparison
equal deleted inserted replaced
1581:357c4bb15701 1582:bd1889029cbb
104 104
105 if (boost::filesystem::exists(path.parent_path())) 105 if (boost::filesystem::exists(path.parent_path()))
106 { 106 {
107 if (!boost::filesystem::is_directory(path.parent_path())) 107 if (!boost::filesystem::is_directory(path.parent_path()))
108 { 108 {
109 throw OrthancException("The subdirectory to be created is already occupied by a regular file"); 109 throw OrthancException(ErrorCode_DirectoryOverFile);
110 } 110 }
111 } 111 }
112 else 112 else
113 { 113 {
114 if (!boost::filesystem::create_directories(path.parent_path())) 114 if (!boost::filesystem::create_directories(path.parent_path()))
115 { 115 {
116 throw OrthancException("Unable to create a subdirectory in the file storage"); 116 throw OrthancException(ErrorCode_FileStorageCannotWrite);
117 } 117 }
118 } 118 }
119 119
120 boost::filesystem::ofstream f; 120 boost::filesystem::ofstream f;
121 f.open(path, std::ofstream::out | std::ios::binary); 121 f.open(path, std::ofstream::out | std::ios::binary);
122 if (!f.good()) 122 if (!f.good())
123 { 123 {
124 throw OrthancException("Unable to create a new file in the file storage"); 124 throw OrthancException(ErrorCode_FileStorageCannotWrite);
125 } 125 }
126 126
127 if (size != 0) 127 if (size != 0)
128 { 128 {
129 f.write(static_cast<const char*>(content), size); 129 f.write(static_cast<const char*>(content), size);
130 if (!f.good()) 130 if (!f.good())
131 { 131 {
132 f.close(); 132 f.close();
133 throw OrthancException("Unable to write to the new file in the file storage"); 133 throw OrthancException(ErrorCode_FileStorageCannotWrite);
134 } 134 }
135 } 135 }
136 136
137 f.close(); 137 f.close();
138 } 138 }