KTextTemplate

exception.h
1/*
2 This file is part of the KTextTemplate library
3
4 SPDX-FileCopyrightText: 2009, 2010 Stephen Kelly <steveire@gmail.com>
5
6 SPDX-License-Identifier: LGPL-2.1-or-later
7
8*/
9
10#ifndef KTEXTTEMPLATE_EXCEPTION_H
11#define KTEXTTEMPLATE_EXCEPTION_H
12
13#include "ktexttemplate_export.h"
14
15#include <QString>
16
17#include <exception>
18
19namespace KTextTemplate
20{
21
22/**
23 Types of errors that can occur while using %KTextTemplate
24*/
25enum Error {
26 NoError,
27 EmptyVariableError,
28 EmptyBlockTagError,
29 InvalidBlockTagError,
30 UnclosedBlockTagError,
31 UnknownFilterError,
32 TagSyntaxError,
33 // VariableSyntaxError,
34
35 VariableNotInContext,
36 ObjectReturnTypeInvalid,
37 CompileFunctionError
38};
39
40/// @headerfile exception.h <KTextTemplate/Exception>
41
42/**
43 @brief An exception for use when implementing template tags.
44
45 The **%Exception** class can be used when implementing
46 AbstractNodeFactory::getNode. An exception can be thrown to indicate that
47 the syntax of a particular tag is invalid.
48
49 For example, the following template markup should throw an error because the
50 include tag should have exactly one argument:
51
52 @code
53 <div>
54 {% include %}
55 </div>
56 @endcode
57
58 The corresponding implementation of IncludeNodeFactory::getNode is
59
60 @code
61 QStringList tagContents = smartSplit( tagContent );
62
63 if ( tagContents.size() != 2 )
64 throw KTextTemplate::Exception( TagSyntaxError,
65 "Error: Include tag takes exactly one argument" );
66
67 // The item at index 0 in the list is the tag name, "include"
68 QString includeName = tagContents.at( 1 );
69 @endcode
70
71 @author Stephen Kelly <steveire@gmail.com>
72*/
73class KTEXTTEMPLATE_EXPORT Exception
74{
75public:
76 /**
77 Creates an exception for the error @p errorCode and the verbose
78 message @p what
79 */
80 Exception(Error errorCode, const QString &what)
81 : m_errorCode(errorCode)
82 , m_what(what)
83 {
84 }
85
86 virtual ~Exception() throw()
87 {
88 }
89
90#ifndef K_DOXYGEN
91 /**
92 @internal
93
94 Returns the verbose message for the exception.
95 */
96 const QString what() const throw()
97 {
98 return m_what;
99 }
100
101 /**
102 @internal
103
104 Returns the error code for the exception.
105 */
106 Error errorCode() const
107 {
108 return m_errorCode;
109 }
110#endif
111
112private:
113 Error m_errorCode;
114 QString m_what;
115};
116}
117
118#endif
An exception for use when implementing template tags.
Definition exception.h:74
Exception(Error errorCode, const QString &what)
Creates an exception for the error errorCode and the verbose message what.
Definition exception.h:80
The KTextTemplate namespace holds all public KTextTemplate API.
Definition Mainpage.dox:8
Error
Types of errors that can occur while using KTextTemplate.
Definition exception.h:25
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:56:17 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.