summaryrefslogtreecommitdiffstats
path: root/libdimensionxx
diff options
context:
space:
mode:
Diffstat (limited to 'libdimensionxx')
-rw-r--r--libdimensionxx/dimensionxx/error.hpp8
-rw-r--r--libdimensionxx/error.cpp5
-rw-r--r--libdimensionxx/png.cpp44
3 files changed, 30 insertions, 27 deletions
diff --git a/libdimensionxx/dimensionxx/error.hpp b/libdimensionxx/dimensionxx/error.hpp
index 072949f..8919895 100644
--- a/libdimensionxx/dimensionxx/error.hpp
+++ b/libdimensionxx/dimensionxx/error.hpp
@@ -22,6 +22,8 @@
#define DIMENSIONXX_ERROR_HPP
#include <dimension.h>
+#include <stdexcept>
+#include <string>
namespace Dimension
{
@@ -33,6 +35,12 @@ namespace Dimension
Severity resilience();
void resilience(Severity resilience);
+
+ class Dimension_Error : public std::runtime_error
+ {
+ public:
+ Dimension_Error(const std::string& str);
+ };
}
#endif /* DIMENSIONXX_ERROR_HPP */
diff --git a/libdimensionxx/error.cpp b/libdimensionxx/error.cpp
index fce453e..948a8c0 100644
--- a/libdimensionxx/error.cpp
+++ b/libdimensionxx/error.cpp
@@ -19,6 +19,8 @@
*************************************************************************/
#include "dimensionxx.hpp"
+#include <stdexcept>
+#include <string>
namespace Dimension
{
@@ -33,4 +35,7 @@ namespace Dimension
{
dmnsn_set_resilience(static_cast<dmnsn_severity>(resilience));
}
+
+ Dimension_Error::Dimension_Error(const std::string& str)
+ : std::runtime_error(str) { }
}
diff --git a/libdimensionxx/png.cpp b/libdimensionxx/png.cpp
index 14b8c4d..1ca3047 100644
--- a/libdimensionxx/png.cpp
+++ b/libdimensionxx/png.cpp
@@ -20,6 +20,8 @@
#include "dimensionxx.hpp"
#include "../libdimension-png/dimension-png.h"
+#include <cstdio>
+#include <stdexcept>
namespace Dimension
{
@@ -38,59 +40,47 @@ namespace Dimension
void PNG_Canvas::write()
{
if (m_written) {
- dmnsn_error(DMNSN_SEVERITY_MEDIUM,
- "Attempt to write canvas to PNG twice.");
- return;
+ throw Dimension_Error("Attempt to write canvas to PNG twice.");
}
if (!m_ostr) {
- dmnsn_error(DMNSN_SEVERITY_MEDIUM,
- "Attempt to write canvas to PNG without an output stream.");
- return;
+ throw Dimension_Error("Attempt to write canvas to PNG without an output"
+ " stream.");
}
FILE* file = fcookie(*m_ostr);
if (!file) {
- dmnsn_error(DMNSN_SEVERITY_MEDIUM,
- "Couldn't create C++/C IO interface when writing canvas"
- " to PNG.");
- return;
+ throw Dimension_Error("Couldn't create C++/C IO interface when writing"
+ " canvas to PNG.");
}
if (dmnsn_png_write_canvas(m_canvas, file)) {
- fclose(file);
- dmnsn_error(DMNSN_SEVERITY_MEDIUM,
- "Writing canvas to PNG failed.");
- return;
+ std::fclose(file);
+ throw Dimension_Error("Writing canvas to PNG failed.");
}
- fclose(file);
+ std::fclose(file);
m_written = true;
}
void PNG_Canvas::read()
{
if (!m_istr) {
- dmnsn_error(DMNSN_SEVERITY_MEDIUM,
- "Attempt to read canvas from PNG without an input stream.");
- return;
+ throw Dimension_Error("Attempt to read canvas from PNG without an input"
+ " stream.");
}
FILE* file = fcookie(*m_istr);
if (!file) {
- dmnsn_error(DMNSN_SEVERITY_MEDIUM,
- "Couldn't create C++/C IO interface when reading canvas"
- " from PNG.");
- return;
+ throw Dimension_Error("Couldn't create C++/C IO interface when reading"
+ " canvas from PNG.");
}
if (!(m_canvas = dmnsn_png_read_canvas(file))) {
- fclose(file);
- dmnsn_error(DMNSN_SEVERITY_MEDIUM,
- "Reading canvas from PNG failed.");
- return;
+ std::fclose(file);
+ throw Dimension_Error("Reading canvas from PNG failed.");
}
- fclose(file);
+ std::fclose(file);
}
}