diff --git a/include/mapnik/unicode.hpp b/include/mapnik/unicode.hpp index e2b109047..3b6d66498 100644 --- a/include/mapnik/unicode.hpp +++ b/include/mapnik/unicode.hpp @@ -43,7 +43,6 @@ public: mapnik::value_unicode_string transcode(const char* data, std::int32_t length = -1) const; ~transcoder(); private: - bool ok_; UConverter * conv_; }; } diff --git a/src/unicode.cpp b/src/unicode.cpp index 6fecf72da..c6a012bc1 100644 --- a/src/unicode.cpp +++ b/src/unicode.cpp @@ -34,13 +34,15 @@ namespace mapnik { transcoder::transcoder (std::string const& encoding) - : ok_(false), - conv_(0) + : conv_(0) { UErrorCode err = U_ZERO_ERROR; conv_ = ucnv_open(encoding.c_str(),&err); - if (U_SUCCESS(err)) ok_ = true; - // TODO ?? + if (!U_SUCCESS(err)) + { + // NOT: conv_ should be null on error so no need to call ucnv_close + throw std::runtime_error(std::string("could not create converter for ") + encoding); + } } mapnik::value_unicode_string transcoder::transcode(const char* data, std::int32_t length) const diff --git a/tests/cpp_tests/exceptions_test.cpp b/tests/cpp_tests/exceptions_test.cpp index cc731fd9f..1bfc826e0 100644 --- a/tests/cpp_tests/exceptions_test.cpp +++ b/tests/cpp_tests/exceptions_test.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -53,6 +54,13 @@ int main(int argc, char** argv) BOOST_TEST(true); } + try { + mapnik::transcoder tr("bogus encoding"); + BOOST_TEST(false); + } catch (...) { + BOOST_TEST(true); + } + mapnik::Map map(256,256); mapnik::rule r; r.set_filter(mapnik::parse_expression("[foo]='bar'"));