Commit 562a2be0 authored by Urs Fleisch's avatar Urs Fleisch

Catch exceptions which could be thrown by 3rd party libraries.

An out_of_range exception from a std::bitset in id3lib terminated the
application, catch exceptions in the Qt event loop.
parent 42ac1c3a
......@@ -362,7 +362,7 @@ if (CMAKE_COMPILER_IS_GNUCC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wundef -Wcast-align -Wall -W -Wpointer-arith -D_REENTRANT")
endif (CMAKE_COMPILER_IS_GNUCC)
if (CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wundef -Wcast-align -Wall -W -Wpointer-arith -fno-exceptions -fno-check-new -fno-common -D_REENTRANT")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wundef -Wcast-align -Wall -W -Wpointer-arith -fno-check-new -fno-common -D_REENTRANT")
check_cxx_compiler_flag(-Woverloaded-virtual _HAVE_W_OVERLOADED_VIRTUAL)
if(_HAVE_W_OVERLOADED_VIRTUAL)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Woverloaded-virtual")
......@@ -370,7 +370,7 @@ if (CMAKE_COMPILER_IS_GNUCXX)
endif (CMAKE_COMPILER_IS_GNUCXX)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wundef -Wcast-align -Wall -W -Wpointer-arith -D_REENTRANT")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wundef -Wcast-align -Wall -W -Wpointer-arith -Woverloaded-virtual -fno-exceptions -fno-common -Werror=return-type -Wweak-vtables -D_REENTRANT")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wundef -Wcast-align -Wall -W -Wpointer-arith -Woverloaded-virtual -fno-common -Werror=return-type -Wweak-vtables -D_REENTRANT")
endif ()
if (MSVC)
# Treat wchar_t as built-in type, else QString::fromWCharArray is unresolved
......
......@@ -37,7 +37,7 @@ if (WITH_GCC_PCH)
message(STATUS "Generating ${_gchFilename}")
file(REMOVE ${_gchFilename})
set(_additionalFlags "-DQT_CORE_LIB -DQT_DBUS_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_XML_LIB -Wundef -Wcast-align -Wall -W -Wpointer-arith -fno-check-new -fno-common -Woverloaded-virtual -fno-exceptions -D_REENTRANT -DQT_NO_EXCEPTIONS -DQT_NO_STL -fvisibility=hidden -fvisibility-inlines-hidden -DQT_ASCII_CAST_WARNINGS -DQT_NO_CAST_TO_ASCII")
set(_additionalFlags "-DQT_CORE_LIB -DQT_DBUS_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_XML_LIB -Wundef -Wcast-align -Wall -W -Wpointer-arith -fno-check-new -fno-common -Woverloaded-virtual -D_REENTRANT -DQT_NO_EXCEPTIONS -DQT_NO_STL -fvisibility=hidden -fvisibility-inlines-hidden -DQT_ASCII_CAST_WARNINGS -DQT_NO_CAST_TO_ASCII")
if (CMAKE_BUILD_TYPE MATCHES Debug)
set(_additionalFlags "${_additionalFlags} -g -DQT_DEBUG")
else (CMAKE_BUILD_TYPE MATCHES Debug)
......
......@@ -6,7 +6,7 @@ set(kde_SRCS
kdesettings.cpp
)
add_definitions(${KDE4_DEFINITIONS} -DKDE_NO_COMPAT)
add_definitions(${KDE4_DEFINITIONS} -DKDE_NO_COMPAT ${KDE4_ENABLE_EXCEPTIONS})
include_directories(${KDE4_INCLUDES})
kde4_add_executable(kid3 ${kde_SRCS})
......
......@@ -31,6 +31,7 @@
#include <kaboutdata.h>
#include <klocale.h>
#include <kconfiggroup.h>
#include <typeinfo>
#include "fileconfig.h"
#include "loadtranslation.h"
#include "kdemainwindow.h"
......@@ -40,6 +41,37 @@
/** To use a constructor with arguments in RESTORE(). */
#define KdeMainWindow_pt_app KdeMainWindow(platformTools, kid3App)
/**
* KApplication subclass which catches exceptions.
*/
class Kid3KdeApplication : public KApplication {
public:
/**
* Send event to receiver.
* @param receiver receiver
* @param event event
* @return return value from receiver's event handler.
*/
virtual bool notify(QObject* receiver, QEvent* event);
};
/**
* Send event to receiver.
* @param receiver receiver
* @param event event
* @return return value from receiver's event handler.
*/
bool Kid3KdeApplication::notify(QObject* receiver, QEvent* event)
{
try {
return KApplication::notify(receiver, event);
} catch (std::exception& ex) {
qWarning("Exception %s (%s) was caught", typeid(ex).name(), ex.what());
}
return false;
}
/**
* Main program.
*
......@@ -64,7 +96,7 @@ int main(int argc, char* argv[])
options.add("+[Dir]", ki18n("%1").subs(QCoreApplication::translate("@default",
QT_TRANSLATE_NOOP("@default", "directory to open"))));
KCmdLineArgs::addCmdLineOptions(options);
KApplication app;
Kid3KdeApplication app;
QString configuredLanguage =
KConfigGroup(KGlobal::config(), "Locale").readEntry("Language");
......
......@@ -30,6 +30,7 @@
#include <QLocale>
#include <QTranslator>
#include <QDir>
#include <typeinfo>
#include "fileconfig.h"
#include "loadtranslation.h"
#include "kid3mainwindow.h"
......@@ -64,6 +65,14 @@ public:
virtual void commitData(QSessionManager& manager) {
emit commitDataRequest(manager);
}
/**
* Send event to receiver.
* @param receiver receiver
* @param event event
* @return return value from receiver's event handler.
*/
virtual bool notify(QObject* receiver, QEvent* event);
};
/**
......@@ -73,6 +82,23 @@ Kid3QtApplication::~Kid3QtApplication()
{
}
/**
* Send event to receiver.
* @param receiver receiver
* @param event event
* @return return value from receiver's event handler.
*/
bool Kid3QtApplication::notify(QObject* receiver, QEvent* event)
{
try {
return QApplication::notify(receiver, event);
} catch (std::exception& ex) {
qWarning("Exception %s (%s) was caught", typeid(ex).name(), ex.what());
}
return false;
}
/**
* Main program.
*
......
Markdown is supported
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