summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2015-02-02 03:38:49 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2015-02-02 03:38:49 +0100
commit75671b4b968987e753ebca072706ed79a8a098bf (patch)
treeee17f9634425d2f8482bd7b4ddbcf179dbf53939
parenta3d6648fa6c0138e1d02408a117f87cbd3407e80 (diff)
downloadMinedMap-75671b4b968987e753ebca072706ed79a8a098bf.tar
MinedMap-75671b4b968987e753ebca072706ed79a8a098bf.zip
Catch exceptions for single regions
-rw-r--r--src/MinedMap.cpp22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/MinedMap.cpp b/src/MinedMap.cpp
index 6207306..d10666b 100644
--- a/src/MinedMap.cpp
+++ b/src/MinedMap.cpp
@@ -117,17 +117,23 @@ static void doRegion(const std::string &input, const std::string &output) {
const std::string tmpfile = output + ".tmp";
- uint32_t image[DIM][DIM] = {};
- World::Region::visitChunks(input.c_str(), [&image] (size_t X, size_t Z, const World::Chunk *chunk) { addChunk(image, X, Z, chunk); });
+ try {
+ uint32_t image[DIM][DIM] = {};
+ World::Region::visitChunks(input.c_str(), [&image] (size_t X, size_t Z, const World::Chunk *chunk) { addChunk(image, X, Z, chunk); });
- writePNG(tmpfile.c_str(), image);
+ writePNG(tmpfile.c_str(), image);
- struct timespec times[2] = {instat.st_mtim, instat.st_mtim};
- if (utimensat(AT_FDCWD, tmpfile.c_str(), times, 0) < 0)
- std::fprintf(stderr, "Warning: failed to set utime on %s: %s\n", tmpfile.c_str(), std::strerror(errno));
+ struct timespec times[2] = {instat.st_mtim, instat.st_mtim};
+ if (utimensat(AT_FDCWD, tmpfile.c_str(), times, 0) < 0)
+ std::fprintf(stderr, "Warning: failed to set utime on %s: %s\n", tmpfile.c_str(), std::strerror(errno));
- if (std::rename(tmpfile.c_str(), output.c_str()) < 0) {
- std::fprintf(stderr, "Unable to save %s: %s\n", output.c_str(), std::strerror(errno));
+ if (std::rename(tmpfile.c_str(), output.c_str()) < 0) {
+ std::fprintf(stderr, "Unable to save %s: %s\n", output.c_str(), std::strerror(errno));
+ unlink(tmpfile.c_str());
+ }
+ }
+ catch (const std::exception& ex) {
+ std::fprintf(stderr, "Failed to generate %s: %s\n", output.c_str(), ex.what());
unlink(tmpfile.c_str());
}
}