Skip to content

Commit fe3123e

Browse files
committed
remove redundant exception translators
Boost.Python already knows how to translate standard C++ exceptions into standard Python exceptions, in particular: std::out_of_range => PyExc_IndexError std::invalid_argument => PyExc_ValueError std::exception => PyExc_RuntimeError Replace all uses of mapnik::value_error with std::invalid_argument
1 parent bd5137a commit fe3123e

6 files changed

Lines changed: 5 additions & 36 deletions

File tree

src/mapnik_envelope.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131

3232
// mapnik
3333
#include <mapnik/geometry/box2d.hpp>
34-
#include <mapnik/value/error.hpp>
3534

3635
using mapnik::coord;
3736
using mapnik::box2d;
@@ -58,7 +57,7 @@ box2d<double> from_string(std::string const& s)
5857
{
5958
std::stringstream ss;
6059
ss << "Could not parse bbox from string: '" << s << "'";
61-
throw mapnik::value_error(ss.str());
60+
throw std::invalid_argument(ss.str());
6261
}
6362
}
6463

src/mapnik_python.cpp

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ void export_logger();
100100
#include <mapnik/image_util.hpp>
101101
#include <mapnik/image_any.hpp>
102102
#include <mapnik/load_map.hpp>
103-
#include <mapnik/value/error.hpp>
104103
#include <mapnik/value.hpp>
105104
#include <mapnik/save_map.hpp>
106105
#include <mapnik/scale_denominator.hpp>
@@ -567,27 +566,6 @@ double scale_denominator(mapnik::Map const& map, bool geographic)
567566
return mapnik::scale_denominator(map.scale(), geographic);
568567
}
569568

570-
// http://docs.python.org/c-api/exceptions.html#standard-exceptions
571-
void value_error_translator(mapnik::value_error const & ex)
572-
{
573-
PyErr_SetString(PyExc_ValueError, ex.what());
574-
}
575-
576-
void runtime_error_translator(std::runtime_error const & ex)
577-
{
578-
PyErr_SetString(PyExc_RuntimeError, ex.what());
579-
}
580-
581-
void out_of_range_error_translator(std::out_of_range const & ex)
582-
{
583-
PyErr_SetString(PyExc_IndexError, ex.what());
584-
}
585-
586-
void standard_error_translator(std::exception const & ex)
587-
{
588-
PyErr_SetString(PyExc_RuntimeError, ex.what());
589-
}
590-
591569
unsigned mapnik_version()
592570
{
593571
return MAPNIK_VERSION;
@@ -716,10 +694,6 @@ BOOST_PYTHON_MODULE(_mapnik)
716694
using mapnik::save_map;
717695
using mapnik::save_map_to_string;
718696

719-
register_exception_translator<std::exception>(&standard_error_translator);
720-
register_exception_translator<std::out_of_range>(&out_of_range_error_translator);
721-
register_exception_translator<mapnik::value_error>(&value_error_translator);
722-
register_exception_translator<std::runtime_error>(&runtime_error_translator);
723697
#if defined(HAVE_CAIRO) && defined(HAVE_PYCAIRO)
724698
register_cairo();
725699
#endif

src/mapnik_style.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#pragma GCC diagnostic pop
3131

3232
// mapnik
33-
#include <mapnik/value/error.hpp>
3433
#include <mapnik/rule.hpp>
3534
#include "mapnik_enumeration.hpp"
3635
#include <mapnik/feature_type_style.hpp>
@@ -54,7 +53,7 @@ void set_image_filters(feature_type_style & style, std::string const& filters)
5453
bool result = parse_image_filters(filters, new_filters);
5554
if (!result)
5655
{
57-
throw mapnik::value_error("failed to parse image-filters: '" + filters + "'");
56+
throw std::invalid_argument("failed to parse image-filters: '" + filters + "'");
5857
}
5958
#ifdef _WINDOWS
6059
style.image_filters() = new_filters;

src/mapnik_svg.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
// mapnik
2626
#include <mapnik/transform/parse_transform.hpp>
2727
#include <mapnik/symbolizer.hpp>
28-
#include <mapnik/value/error.hpp>
2928

3029
#pragma GCC diagnostic push
3130
#include <mapnik/warning_ignore.hpp>
@@ -51,7 +50,7 @@ void set_svg_transform(T& symbolizer, std::string const& transform_wkt)
5150
ss << "Could not parse transform from '"
5251
<< transform_wkt
5352
<< "', expected SVG transform attribute";
54-
throw mapnik::value_error(ss.str());
53+
throw std::invalid_argument(ss.str());
5554
}
5655
symbolizer.set_image_transform(trans_expr);
5756
}

src/mapnik_symbolizer.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
#include "mapnik_enumeration.hpp"
4141
#include "mapnik_svg.hpp"
4242
#include <mapnik/expression_node.hpp>
43-
#include <mapnik/value/error.hpp>
4443
#include <mapnik/marker_cache.hpp> // for known_svg_prefix_
4544
#include <mapnik/group/group_layout.hpp>
4645
#include <mapnik/group/group_rule.hpp>

src/python_grid_utils.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
#include <mapnik/grid/grid_renderer.hpp>
3737
#include <mapnik/grid/grid.hpp>
3838
#include <mapnik/grid/grid_view.hpp>
39-
#include <mapnik/value/error.hpp>
4039
#include <mapnik/feature.hpp>
4140
#include <mapnik/feature_kv_iterator.hpp>
4241
#include "python_grid_utils.hpp"
@@ -271,7 +270,7 @@ boost::python::dict grid_encode( T const& grid, std::string const& format, bool
271270
{
272271
std::stringstream s;
273272
s << "'utf' is currently the only supported encoding format.";
274-
throw mapnik::value_error(s.str());
273+
throw std::invalid_argument(s.str());
275274
}
276275
}
277276

@@ -307,7 +306,7 @@ void render_layer_for_grid(mapnik::Map const& map,
307306
{
308307
std::stringstream s;
309308
s << "list of field names must be strings";
310-
throw mapnik::value_error(s.str());
309+
throw std::invalid_argument(s.str());
311310
}
312311
}
313312

0 commit comments

Comments
 (0)