~ubuntu-branches/ubuntu/precise/grantlee/precise

« back to all changes in this revision

Viewing changes to corelib/exception.h

  • Committer: Bazaar Package Importer
  • Author(s): Harald Sitter
  • Date: 2010-06-11 23:41:45 UTC
  • Revision ID: james.westby@ubuntu.com-20100611234145-oas7rhdrbwy8j55c
Tags: upstream-0.1.1
ImportĀ upstreamĀ versionĀ 0.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  This file is part of the Grantlee template system.
 
3
 
 
4
  Copyright (c) 2009,2010 Stephen Kelly <steveire@gmail.com>
 
5
 
 
6
  This library is free software; you can redistribute it and/or
 
7
  modify it under the terms of the GNU Lesser General Public
 
8
  License as published by the Free Software Foundation; either version
 
9
  2 of the Licence, or (at your option) any later version.
 
10
 
 
11
  This library is distributed in the hope that it will be useful,
 
12
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
  Library General Public License for more details.
 
15
 
 
16
  You should have received a copy of the GNU Lesser General Public
 
17
  License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 
18
 
 
19
*/
 
20
 
 
21
#ifndef GRANTLEE_EXCEPTION_H
 
22
#define GRANTLEE_EXCEPTION_H
 
23
 
 
24
#include <QtCore/QString>
 
25
 
 
26
#include <exception>
 
27
 
 
28
namespace Grantlee
 
29
{
 
30
 
 
31
 
 
32
/**
 
33
  Types of errors that can occur while using %Grantlee
 
34
*/
 
35
enum Error {
 
36
  NoError,
 
37
  EmptyVariableError,
 
38
  EmptyBlockTagError,
 
39
  InvalidBlockTagError,
 
40
  UnclosedBlockTagError,
 
41
  UnknownFilterError,
 
42
  TagSyntaxError,
 
43
//   VariableSyntaxError,
 
44
 
 
45
  VariableNotInContext,
 
46
  ObjectReturnTypeInvalid,
 
47
  CompileFunctionError
 
48
};
 
49
 
 
50
 
 
51
/// @headerfile exception.h grantlee/exception.h
 
52
 
 
53
/**
 
54
  @brief An exception for use when implementing template tags.
 
55
 
 
56
  The exception class can be used when implementing AbstractNodeFactory::getNode. An exception can be thrown to indicate that
 
57
  the syntax of a particular tag is invalid.
 
58
 
 
59
  For example, the following template markup should throw an error because the include tag should have exactly one argument:
 
60
  @code
 
61
    <div>
 
62
      {% include %}
 
63
    </div>
 
64
  @endcode
 
65
 
 
66
  The corresponding implementation of IncludeNodeFactory::getNode is
 
67
 
 
68
  @code
 
69
    QStringList tagContents = smartSplit( tagContent );
 
70
 
 
71
    if ( tagContents.size() != 2 )
 
72
      throw Grantlee::Exception( TagSyntaxError, "Error: Include tag takes exactly one argument" );
 
73
 
 
74
    // The item at index 0 in the list is the tag name, "include"
 
75
    QString includeName = tagContents.at( 1 );
 
76
  @endcode
 
77
 
 
78
*/
 
79
class GRANTLEE_CORE_EXPORT Exception
 
80
{
 
81
public:
 
82
  /**
 
83
    Creates an exception for the error @p errorCode and the verbose message @p what
 
84
  */
 
85
  Exception( Error errorCode, const QString &what )
 
86
    : m_errorCode( errorCode ), m_what( what ) {}
 
87
 
 
88
  virtual ~Exception() throw() {}
 
89
 
 
90
#ifndef Q_QDOC
 
91
  /**
 
92
    @internal
 
93
 
 
94
    Returns the verbose message for the exception.
 
95
  */
 
96
  const QString what() const throw() {
 
97
    return m_what;
 
98
  }
 
99
 
 
100
  /**
 
101
    @internal
 
102
 
 
103
    Returns the error code for the exception.
 
104
  */
 
105
  Error errorCode() const {
 
106
    return m_errorCode;
 
107
  }
 
108
#endif
 
109
 
 
110
private:
 
111
  Error m_errorCode;
 
112
  QString m_what;
 
113
};
 
114
 
 
115
}
 
116
 
 
117
#endif
 
118