KTextTemplate::Exception Class

class KTextTemplate::Exception

An exception for use when implementing template tags. More...

Header: #include <KTextTemplate/Exception>
CMake: find_package(KF6 REQUIRED COMPONENTS TextTemplate)
target_link_libraries(mytarget PRIVATE KF6::TextTemplate)

Public Functions

Exception(KTextTemplate::Error errorCode, const QString &what)

Detailed Description

The Exception class can be used when implementing AbstractNodeFactory::getNode. An exception can be thrown to indicate that the syntax of a particular tag is invalid.

For example, the following template markup should throw an error because the include tag should have exactly one argument:

<div>
  {% include %}
</div>

The corresponding implementation of IncludeNodeFactory::getNode is

QStringList tagContents = smartSplit( tagContent );

if ( tagContents.size() != 2 )
  throw KTextTemplate::Exception( TagSyntaxError,
    "Error: Include tag takes exactly one argument" );

// The item at index 0 in the list is the tag name, "include"
QString includeName = tagContents.at( 1 );

Member Function Documentation

Exception::Exception(KTextTemplate::Error errorCode, const QString &what)

Creates an exception for the error errorCode and the verbose message what