diff --git a/src/plugins/texteditor/generichighlighter/highlightdefinition.cpp b/src/plugins/texteditor/generichighlighter/highlightdefinition.cpp index 0f6556e50e1..c1ad484dbfb 100644 --- a/src/plugins/texteditor/generichighlighter/highlightdefinition.cpp +++ b/src/plugins/texteditor/generichighlighter/highlightdefinition.cpp @@ -35,6 +35,7 @@ #include "itemdata.h" #include "reuse.h" +#include #include using namespace TextEditor; @@ -45,11 +46,16 @@ namespace { template QSharedPointer createHelper(const QString &name, Container &container) { - if (name.isEmpty()) - throw HighlighterException(); + if (name.isEmpty()) { + throw HighlighterException( + QCoreApplication::translate("GenericHighlighter", "Element name is empty")); + } - if (container.contains(name)) - throw HighlighterException(); + if (container.contains(name)) { + throw HighlighterException( + QCoreApplication::translate("GenericHighlighter", + "Duplicate element name \"%1\"").arg(name)); + } return container.insert(name, QSharedPointer(new Element)).value(); } @@ -59,8 +65,11 @@ QSharedPointer findHelper(const QString &name, const Container &container) { typename Container::const_iterator it = container.find(name); - if (it == container.end()) - throw HighlighterException(); + if (it == container.end()) { + throw HighlighterException( + QCoreApplication::translate("GenericHighlighter", + "name \"%1\" not found").arg(name)); + } return it.value(); } diff --git a/src/plugins/texteditor/generichighlighter/highlighter.cpp b/src/plugins/texteditor/generichighlighter/highlighter.cpp index 74f2898f0aa..07e26893ab6 100644 --- a/src/plugins/texteditor/generichighlighter/highlighter.cpp +++ b/src/plugins/texteditor/generichighlighter/highlighter.cpp @@ -38,8 +38,9 @@ #include "reuse.h" #include "tabsettings.h" -#include -#include +#include + +#include using namespace TextEditor; using namespace Internal; @@ -205,7 +206,11 @@ void Highlighter::highlightBlock(const QString &text) } TextDocumentLayout::setParentheses(currentBlock(), parentheses); - } catch (const HighlighterException &) { + } catch (const HighlighterException &e) { + Core::MessageManager::write( + QCoreApplication::translate("GenericHighlighter", + "Generic highlighter error: ") + e.message(), + Core::MessageManager::WithFocus); m_isBroken = true; } } @@ -388,8 +393,10 @@ void Highlighter::changeContext(const QString &contextName, if (contextName.startsWith(kPop)) { QStringList list = contextName.split(kHash, QString::SkipEmptyParts); for (int i = 0; i < list.size(); ++i) { - if (m_contexts.isEmpty()) - throw HighlighterException(); + if (m_contexts.isEmpty()) { + throw HighlighterException( + QCoreApplication::translate("GenericHighlighter", "Reached empty context")); + } m_contexts.pop_back(); } diff --git a/src/plugins/texteditor/generichighlighter/highlighterexception.h b/src/plugins/texteditor/generichighlighter/highlighterexception.h index eabb3d95081..2f55cee4ebf 100644 --- a/src/plugins/texteditor/generichighlighter/highlighterexception.h +++ b/src/plugins/texteditor/generichighlighter/highlighterexception.h @@ -31,8 +31,20 @@ #ifndef HIGHLIGHTEREXCEPTION_H #define HIGHLIGHTEREXCEPTION_H +#include + namespace TextEditor { -namespace Internal { class HighlighterException {}; } +namespace Internal { +class HighlighterException +{ +public: + HighlighterException(const QString &msg) : m_message(msg) {} + QString message() const { return m_message; } + +private: + QString m_message; +}; +} } // namespace TextEditor #endif // HIGHLIGHTEREXCEPTION_H diff --git a/src/plugins/texteditor/generichighlighter/manager.cpp b/src/plugins/texteditor/generichighlighter/manager.cpp index e385c88041c..d44eec53749 100644 --- a/src/plugins/texteditor/generichighlighter/manager.cpp +++ b/src/plugins/texteditor/generichighlighter/manager.cpp @@ -39,14 +39,14 @@ #include #include +#include #include #include #include #include +#include #include -#include -#include #include #include #include @@ -175,7 +175,11 @@ QSharedPointer Manager::definition(const QString &id) m_isBuildingDefinition.insert(id); try { reader.parse(source); - } catch (const HighlighterException &) { + } catch (const HighlighterException &e) { + Core::MessageManager::write( + QCoreApplication::translate("GenericHighlighter", + "Generic highlighter error: ") + e.message(), + Core::MessageManager::WithFocus); definition.clear(); } m_isBuildingDefinition.remove(id);