Commit 4430d61b authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

proper error messages using DUNE_THROW

parent 43414df5
...@@ -4,6 +4,7 @@ dune_add_library("filesystem" OBJECT ...@@ -4,6 +4,7 @@ dune_add_library("filesystem" OBJECT
#install headers #install headers
install(FILES install(FILES
enum.hh enum.hh
errors.hh
filesystem.hh filesystem.hh
lagrangepoints.hh lagrangepoints.hh
lagrangepoints.impl.hh lagrangepoints.impl.hh
......
#pragma once
#include <dune/common/exceptions.hh>
/**
* \file
* \brief Macro for wrapping error checks and throwing exceptions
*/
namespace Dune {
class VtkError : public Exception {};
}
/**
* \brief check if condition \a cond holds; otherwise, throw a VtkError.
*/
#define VTK_ASSERT(cond, text) \
do { \
if (!(cond)) \
DUNE_THROW(Dune::VtkError, text); \
} while (false)
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <dune/common/classname.hh> #include <dune/common/classname.hh>
#include <dune/common/version.hh> #include <dune/common/version.hh>
#include "utility/errors.hh"
#include "utility/filesystem.hh" #include "utility/filesystem.hh"
#include "utility/string.hh" #include "utility/string.hh"
...@@ -32,7 +33,7 @@ void VtkReader<Grid,Creator>::read (std::string const& filename, bool fillCreato ...@@ -32,7 +33,7 @@ void VtkReader<Grid,Creator>::read (std::string const& filename, bool fillCreato
} else if (ext == ".pvtu") { } else if (ext == ".pvtu") {
readParallelFileFromStream(input, comm().rank(), comm().size(), fillCreator); readParallelFileFromStream(input, comm().rank(), comm().size(), fillCreator);
} else { } else {
DUNE_THROW(IOError, "File has unknown file-extension '" << ext << "'. Allowed are only '.vtu' and '.pvtu'."); DUNE_THROW(Dune::VtkError, "File has unknown file-extension '" << ext << "'. Allowed are only '.vtu' and '.pvtu'.");
} }
} }
...@@ -56,16 +57,16 @@ void VtkReader<Grid,Creator>::readSerialFileFromStream (std::ifstream& input, bo ...@@ -56,16 +57,16 @@ void VtkReader<Grid,Creator>::readSerialFileFromStream (std::ifstream& input, bo
auto attr = parseXml(line, closed); auto attr = parseXml(line, closed);
if (!attr["type"].empty()) if (!attr["type"].empty())
assert(attr["type"] == "UnstructuredGrid"); VTK_ASSERT(attr["type"] == "UnstructuredGrid", "VtkReader supports UnstructuredGrid types");
if (!attr["version"].empty()) if (!attr["version"].empty())
assert(std::stod(attr["version"]) == 1.0); VTK_ASSERT(std::stod(attr["version"]) == 1.0, "File format must be 1.0");
if (!attr["byte_order"].empty()) if (!attr["byte_order"].empty())
assert(attr["byte_order"] == "LittleEndian"); VTK_ASSERT(attr["byte_order"] == "LittleEndian", "LittleEndian byte order supported");
if (!attr["header_type"].empty()) if (!attr["header_type"].empty())
assert(attr["header_type"] == "UInt64"); VTK_ASSERT(attr["header_type"] == "UInt64", "Header integer type must be UInt64");
if (!attr["compressor"].empty()) { if (!attr["compressor"].empty()) {
compressor = attr["compressor"]; compressor = attr["compressor"];
assert(compressor == "vtkZLibDataCompressor"); // only ZLib compression supported VTK_ASSERT(compressor == "vtkZLibDataCompressor", "Only ZLib compression supported");
} }
section = VTK_FILE; section = VTK_FILE;
} }
...@@ -79,7 +80,7 @@ void VtkReader<Grid,Creator>::readSerialFileFromStream (std::ifstream& input, bo ...@@ -79,7 +80,7 @@ void VtkReader<Grid,Creator>::readSerialFileFromStream (std::ifstream& input, bo
bool closed = false; bool closed = false;
auto attr = parseXml(line, closed); auto attr = parseXml(line, closed);
assert(attr.count("NumberOfPoints") > 0 && attr.count("NumberOfCells") > 0); VTK_ASSERT(attr.count("NumberOfPoints") > 0 && attr.count("NumberOfCells") > 0, "Number of points or cells in file must be > 0");
numberOfPoints_ = std::stoul(attr["NumberOfPoints"]); numberOfPoints_ = std::stoul(attr["NumberOfPoints"]);
numberOfCells_ = std::stoul(attr["NumberOfCells"]); numberOfCells_ = std::stoul(attr["NumberOfCells"]);
section = PIECE; section = PIECE;
...@@ -129,7 +130,7 @@ void VtkReader<Grid,Creator>::readSerialFileFromStream (std::ifstream& input, bo ...@@ -129,7 +130,7 @@ void VtkReader<Grid,Creator>::readSerialFileFromStream (std::ifstream& input, bo
data_offset = 0; data_offset = 0;
if (!attr["offset"].empty()) { if (!attr["offset"].empty()) {
data_offset = std::stoul(attr["offset"]); data_offset = std::stoul(attr["offset"]);
assert(data_format == "appended"); VTK_ASSERT(data_format == "appended", "Attribute 'offset' only supported by appended mode");
} }
// Store attributes of DataArray // Store attributes of DataArray
...@@ -156,7 +157,7 @@ void VtkReader<Grid,Creator>::readSerialFileFromStream (std::ifstream& input, bo ...@@ -156,7 +157,7 @@ void VtkReader<Grid,Creator>::readSerialFileFromStream (std::ifstream& input, bo
else if (section == CELLS) else if (section == CELLS)
section = CELLS_DATA_ARRAY; section = CELLS_DATA_ARRAY;
else else
DUNE_THROW(Exception, "Wrong section for <DataArray>"); DUNE_THROW(Dune::VtkError, "Wrong section for <DataArray>");
} }
else if (line.substr(1,10) == "/DataArray") { else if (line.substr(1,10) == "/DataArray") {
if (section == PD_DATA_ARRAY) if (section == PD_DATA_ARRAY)
...@@ -168,13 +169,13 @@ void VtkReader<Grid,Creator>::readSerialFileFromStream (std::ifstream& input, bo ...@@ -168,13 +169,13 @@ void VtkReader<Grid,Creator>::readSerialFileFromStream (std::ifstream& input, bo
else if (section == CELLS_DATA_ARRAY) else if (section == CELLS_DATA_ARRAY)
section = CELLS; section = CELLS;
else else
DUNE_THROW(Exception, "Wrong section for </DataArray>"); DUNE_THROW(Dune::VtkError, "Wrong section for </DataArray>");
} }
else if (isSection(line, "AppendedData", section, VTK_FILE)) { else if (isSection(line, "AppendedData", section, VTK_FILE)) {
bool closed = false; bool closed = false;
auto attr = parseXml(line, closed); auto attr = parseXml(line, closed);
if (!attr["encoding"].empty()) if (!attr["encoding"].empty())
assert(attr["encoding"] == "raw"); // base64 encoding not supported VTK_ASSERT(attr["encoding"] == "raw", "base64 encoding not supported");
offset0_ = findAppendedDataPosition(input); offset0_ = findAppendedDataPosition(input);
if (dataArray_["points"].type == Vtk::FLOAT32) if (dataArray_["points"].type == Vtk::FLOAT32)
...@@ -223,7 +224,7 @@ void VtkReader<Grid,Creator>::readSerialFileFromStream (std::ifstream& input, bo ...@@ -223,7 +224,7 @@ void VtkReader<Grid,Creator>::readSerialFileFromStream (std::ifstream& input, bo
} }
if (section != NO_SECTION) if (section != NO_SECTION)
DUNE_THROW(IOError, "VTK-File is incomplete. It must end with </VTKFile>!"); DUNE_THROW(Dune::VtkError, "VTK-File is incomplete. It must end with </VTKFile>!");
if (fillCreator) if (fillCreator)
fillGridCreator(); fillGridCreator();
...@@ -244,15 +245,15 @@ void VtkReader<Grid,Creator>::readParallelFileFromStream (std::ifstream& input, ...@@ -244,15 +245,15 @@ void VtkReader<Grid,Creator>::readParallelFileFromStream (std::ifstream& input,
auto attr = parseXml(line, closed); auto attr = parseXml(line, closed);
if (!attr["type"].empty()) if (!attr["type"].empty())
assert(attr["type"] == "PUnstructuredGrid"); VTK_ASSERT(attr["type"] == "PUnstructuredGrid", "VtkReader supports PUnstructuredGrid types");
if (!attr["version"].empty()) if (!attr["version"].empty())
assert(std::stod(attr["version"]) == 1.0); VTK_ASSERT(std::stod(attr["version"]) == 1.0, "File format must be 1.0");
if (!attr["byte_order"].empty()) if (!attr["byte_order"].empty())
assert(attr["byte_order"] == "LittleEndian"); VTK_ASSERT(attr["byte_order"] == "LittleEndian", "LittleEndian byte order supported");
if (!attr["header_type"].empty()) if (!attr["header_type"].empty())
assert(attr["header_type"] == "UInt64"); VTK_ASSERT(attr["header_type"] == "UInt64", "Header integer type must be UInt64");
if (!attr["compressor"].empty()) if (!attr["compressor"].empty())
assert(attr["compressor"] == "vtkZLibDataCompressor"); // only ZLib compression supported VTK_ASSERT(attr["compressor"] == "vtkZLibDataCompressor", "Only ZLib compression supported");
section = VTK_FILE; section = VTK_FILE;
} }
else if (isSection(line, "/VTKFile", section, VTK_FILE)) else if (isSection(line, "/VTKFile", section, VTK_FILE))
...@@ -265,7 +266,7 @@ void VtkReader<Grid,Creator>::readParallelFileFromStream (std::ifstream& input, ...@@ -265,7 +266,7 @@ void VtkReader<Grid,Creator>::readParallelFileFromStream (std::ifstream& input,
bool closed = false; bool closed = false;
auto attr = parseXml(line, closed); auto attr = parseXml(line, closed);
assert(attr.count("Source") > 0); VTK_ASSERT(attr.count("Source") > , "No source files for partitions provided");
pieces_.push_back(attr["Source"]); pieces_.push_back(attr["Source"]);
} }
...@@ -274,7 +275,7 @@ void VtkReader<Grid,Creator>::readParallelFileFromStream (std::ifstream& input, ...@@ -274,7 +275,7 @@ void VtkReader<Grid,Creator>::readParallelFileFromStream (std::ifstream& input,
} }
if (section != NO_SECTION) if (section != NO_SECTION)
DUNE_THROW(IOError, "VTK-File is incomplete. It must end with </VTKFile>!"); DUNE_THROW(Dune::VtkError, "VTK-File is incomplete. It must end with </VTKFile>!");
if (fillCreator) if (fillCreator)
fillGridCreator(); fillGridCreator();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment