From e95886f327fe8247dcb1273f59812ac4b9251c54 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Tue, 31 Jul 2012 10:45:38 -0700 Subject: [PATCH] catch exceptions upon startup --- demo/viewer/main.cpp | 87 ++++++++++++++++++++++++-------------------- 1 file changed, 47 insertions(+), 40 deletions(-) diff --git a/demo/viewer/main.cpp b/demo/viewer/main.cpp index 905844720..c5cb4ad4c 100644 --- a/demo/viewer/main.cpp +++ b/demo/viewer/main.cpp @@ -36,52 +36,59 @@ int main( int argc, char **argv ) using mapnik::datasource_cache; using mapnik::freetype_engine; - QCoreApplication::setOrganizationName("Mapnik"); - QCoreApplication::setOrganizationDomain("mapnik.org"); - QCoreApplication::setApplicationName("Viewer"); - - QSettings settings("viewer.ini",QSettings::IniFormat); - - // register input plug-ins - QString plugins_dir = settings.value("mapnik/plugins_dir", - QVariant("/usr/local/lib/mapnik/input/")).toString(); - datasource_cache::instance()->register_datasources(plugins_dir.toStdString()); - // register fonts - int count = settings.beginReadArray("mapnik/fonts"); - for (int index=0; index < count; ++index) + try { - settings.setArrayIndex(index); - QString font_dir = settings.value("dir").toString(); - freetype_engine::register_fonts(font_dir.toStdString()); - } - settings.endArray(); + QCoreApplication::setOrganizationName("Mapnik"); + QCoreApplication::setOrganizationDomain("mapnik.org"); + QCoreApplication::setApplicationName("Viewer"); + QSettings settings("viewer.ini",QSettings::IniFormat); - QApplication app( argc, argv ); - MainWindow window; - window.show(); - if (argc > 1) window.open(argv[1]); - if (argc >= 3) - { - QStringList list = QString(argv[2]).split(","); - if (list.size()==4) + // register input plug-ins + QString plugins_dir = settings.value("mapnik/plugins_dir", + QVariant("/usr/local/lib/mapnik/input/")).toString(); + datasource_cache::instance()->register_datasources(plugins_dir.toStdString()); + // register fonts + int count = settings.beginReadArray("mapnik/fonts"); + for (int index=0; index < count; ++index) + { + settings.setArrayIndex(index); + QString font_dir = settings.value("dir").toString(); + freetype_engine::register_fonts(font_dir.toStdString()); + } + settings.endArray(); + + QApplication app( argc, argv ); + MainWindow window; + window.show(); + if (argc > 1) window.open(argv[1]); + if (argc >= 3) + { + QStringList list = QString(argv[2]).split(","); + if (list.size()==4) + { + bool ok; + double x0 = list[0].toDouble(&ok); + double y0 = list[1].toDouble(&ok); + double x1 = list[2].toDouble(&ok); + double y1 = list[3].toDouble(&ok); + if (ok) window.set_default_extent(x0,y0,x1,y1); + } + } + else + { + window.zoom_all(); + } + if (argc == 4) { bool ok; - double x0 = list[0].toDouble(&ok); - double y0 = list[1].toDouble(&ok); - double x1 = list[2].toDouble(&ok); - double y1 = list[3].toDouble(&ok); - if (ok) window.set_default_extent(x0,y0,x1,y1); + double scaling_factor = QString(argv[3]).toDouble(&ok); + if (ok) window.set_scaling_factor(scaling_factor); } + return app.exec(); } - else + catch (std::exception const& ex) { - window.zoom_all(); + std::cerr << "Could not start viewer: '" << ex.what() << "'\n"; + return 1; } - if (argc == 4) - { - bool ok; - double scaling_factor = QString(argv[3]).toDouble(&ok); - if (ok) window.set_scaling_factor(scaling_factor); - } - return app.exec(); }