diff --git a/src/plugins/genericeditor/highlighter.cpp b/src/plugins/genericeditor/highlighter.cpp
index 67b90fe0f6de618fe09e63b0917f82cfe50f0335..416ee87214176c38206156e7b1c95264df6adee7 100644
--- a/src/plugins/genericeditor/highlighter.cpp
+++ b/src/plugins/genericeditor/highlighter.cpp
@@ -422,8 +422,12 @@ void Highlighter::pushDynamicContext(const QSharedPointer<Context> &baseContext)
 
 void Highlighter::setCurrentContext()
 {
-    if (m_contexts.isEmpty())
-        throw HighlighterException();
+    if (m_contexts.isEmpty()) {
+        // This is not supposed to happen. However, there might be broken files (for example, the
+        // PHP definition) which will cause this behaviour. In such cases just pushing the default
+        // context is enough to keep highlighter working.
+        m_contexts.push_back(m_defaultContext);
+    }
     m_currentContext = m_contexts.back();
 }