"Fossies" - the Fresh Open Source Software Archive

Member "highlight-3.57-x64/src/include/Diluculum/LuaExceptions.hpp" (12 May 2020, 6061 Bytes) of package /windows/www/highlight-3.57-x64.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /******************************************************************************\
    2 * LuaExceptions.hpp                                                            *
    3 * Exceptions related to Lua errors.                                            *
    4 *                                                                              *
    5 *                                                                              *
    6 * Copyright (C) 2005-2013 by Leandro Motta Barros.                             *
    7 *                                                                              *
    8 * Permission is hereby granted, free of charge, to any person obtaining a copy *
    9 * of this software and associated documentation files (the "Software"), to     *
   10 * deal in the Software without restriction, including without limitation the   *
   11 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or  *
   12 * sell copies of the Software, and to permit persons to whom the Software is   *
   13 * furnished to do so, subject to the following conditions:                     *
   14 *                                                                              *
   15 * The above copyright notice and this permission notice shall be included in   *
   16 * all copies or substantial portions of the Software.                          *
   17 *                                                                              *
   18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR   *
   19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,     *
   20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE *
   21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER       *
   22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING      *
   23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS *
   24 * IN THE SOFTWARE.                                                             *
   25 \******************************************************************************/
   26 
   27 #ifndef _DILUCULUM_LUA_EXCEPTIONS_HPP_
   28 #define _DILUCULUM_LUA_EXCEPTIONS_HPP_
   29 
   30 #include <stdexcept>
   31 #include <Diluculum/Types.hpp>
   32 #include <Diluculum/LuaValue.hpp>
   33 
   34 
   35 namespace Diluculum
   36 {
   37    /// A generic Lua-related error.
   38    class LuaError: public std::runtime_error
   39    {
   40       public:
   41          /** Constructs a \c LuaError object.
   42           *  @param what The message associated with the error.
   43           */
   44          LuaError (const char* what)
   45             : std::runtime_error (what)
   46          { }
   47    };
   48 
   49 
   50 
   51    /// A Lua run-time error.
   52    class LuaRunTimeError: public LuaError
   53    {
   54       public:
   55          /** Constructs a \c LuaRunTimeError object.
   56           *  @param what The message associated with the error. Typically will
   57           *              be the error message issued by the Lua interpreter.
   58           */
   59          LuaRunTimeError (const char* what)
   60             : LuaError (what)
   61          { }
   62    };
   63 
   64 
   65 
   66    /// A Lua file-related error.
   67    class LuaFileError: public LuaError
   68    {
   69       public:
   70          /** Constructs a \c LuaFileError object.
   71           *  @param what The message associated with the error.
   72           */
   73          LuaFileError (const char* what)
   74             : LuaError (what)
   75          { }
   76    };
   77 
   78 
   79 
   80    /// An error while interpreting a chunk of Lua code.
   81    class LuaSyntaxError: public LuaError
   82    {
   83       public:
   84          /** Constructs a \c LuaSyntaxError object.
   85           *  @param what The message associated with the error. Typically will be
   86           *              the error message issued by the Lua interpreter.
   87           */
   88          LuaSyntaxError (const char* what)
   89             : LuaError (what)
   90          { }
   91    };
   92 
   93 
   94 
   95    /// A memory error reported by Lua.
   96    class LuaMemoryError: public LuaError
   97    {
   98       public:
   99          /** Constructs a \c LuaMemoryError object.
  100           *  @param what The message associated with the error.
  101           */
  102          LuaMemoryError (const char* what)
  103             : LuaError (what)
  104          { }
  105    };
  106 
  107 
  108 
  109    /// An error while executing the Lua error handler.
  110    class LuaErrorError: public LuaError
  111    {
  112       public:
  113          /** Constructs a \c LuaErrorError object.
  114           *  @param what The message associated with the error.
  115           */
  116          LuaErrorError (const char* what)
  117             : LuaError (what)
  118          { }
  119    };
  120 
  121 
  122 
  123    /// An error related to types when doing some Lua-related processing.
  124    class LuaTypeError: public LuaError
  125    {
  126       public:
  127          /** Constructs a \c LuaTypeError object.
  128           *  @param what The message associated with the error.
  129           */
  130          LuaTypeError (const char* what)
  131             : LuaError (what)
  132          { }
  133    };
  134 
  135 
  136 
  137    /** An error that happens when a certain type is expected but another one is
  138     *  found.
  139     */
  140    class TypeMismatchError: public LuaError
  141    {
  142       public:
  143          /** Constructs a \c TypeMismatchError object.
  144           *  @param expectedType The type that was expected.
  145           *  @param foundType The type that was actually found.
  146           */
  147          TypeMismatchError (const std::string& expectedType,
  148                             const std::string& foundType);
  149 
  150          /** Destroys a \c TypeMismatchError object.
  151           *  @note This was defined just to pretend that the destructor does not
  152           *        throw any exception. While this is something that I cannot
  153           *        guarantee (at least with this implementation), I believe this
  154           *        not a very dangerous lie.
  155           */
  156          ~TypeMismatchError() throw() { };
  157 
  158          /// Returns the type that was expected.
  159          std::string getExpectedType() const { return expectedType_; }
  160 
  161          /// Returns the type that was actually found.
  162          std::string getFoundType() const { return foundType_; }
  163 
  164       private:
  165          /// The type that was expected.
  166          std::string expectedType_;
  167 
  168          /// The type that was actually found.
  169          std::string foundType_;
  170    };
  171 
  172 } // namespace Diluculum
  173 
  174 
  175 #endif // _DILUCULUM_LUA_EXCEPTIONS_HPP_