2009-07-22 02:10:36 +02:00
|
|
|
// Copyright (c) 2009, Niels Martin Hansen
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
|
|
// and/or other materials provided with the distribution.
|
|
|
|
// * Neither the name of the Aegisub Group nor the names of its contributors
|
|
|
|
// may be used to endorse or promote products derived from this software
|
|
|
|
// without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
// POSSIBILITY OF SUCH DAMAGE.
|
2009-07-29 07:43:02 +02:00
|
|
|
//
|
|
|
|
// Aegisub Project http://www.aegisub.org/
|
|
|
|
|
2009-10-05 02:06:11 +02:00
|
|
|
#pragma once
|
2009-07-22 02:10:36 +02:00
|
|
|
|
2012-09-25 01:35:27 +02:00
|
|
|
#include <string>
|
2009-07-30 06:24:23 +02:00
|
|
|
|
2010-05-21 03:13:36 +02:00
|
|
|
namespace agi {
|
2009-07-30 06:24:23 +02:00
|
|
|
/// @class Exception
|
2009-08-05 22:51:32 +02:00
|
|
|
/// @brief Base class for all exceptions in Aegisub.
|
2009-07-30 06:24:23 +02:00
|
|
|
///
|
2009-08-05 22:51:32 +02:00
|
|
|
/// All exceptions thrown by Aegisub should derive from this class.
|
|
|
|
/// It is incorrect to throw anything that is not a subclass of this.
|
|
|
|
///
|
|
|
|
/// However, there are no public constructors for this class, it should
|
|
|
|
/// not be instantiated and thrown directly. Throw instances of a
|
|
|
|
/// relevant sub class, declare a new one if necessary. It is allowed to
|
|
|
|
/// declare sub classes of Exception and derivates in private headers
|
|
|
|
/// and even inside source files, as long as a caller has a chance to
|
|
|
|
/// catch the exception thrown.
|
|
|
|
///
|
|
|
|
/// When throwing exceptions, throw temporaries, not heap allocated
|
|
|
|
/// objects. (C++ FAQ Lite 17.6.) I.e. this is correct:
|
|
|
|
/// @code
|
Merge the dynamic menu, hotkey and toolbar branch to trunk. This doesn't include Windows support as vs2008 was being a major pain. This involves revisions r4921:4950, r4961:5002, r5005:5006, r5008:5056, r5062:5065, r5072, r5081:5082, r5087, r5096:5110, r5124:5125. Updates #1258.
Originally committed to SVN as r5126.
2011-01-05 14:00:46 +01:00
|
|
|
/// throw agi::SomeException("Message for exception");
|
2009-08-05 22:51:32 +02:00
|
|
|
/// @endcode
|
|
|
|
/// This is wrong:
|
|
|
|
/// @code
|
Merge the dynamic menu, hotkey and toolbar branch to trunk. This doesn't include Windows support as vs2008 was being a major pain. This involves revisions r4921:4950, r4961:5002, r5005:5006, r5008:5056, r5062:5065, r5072, r5081:5082, r5087, r5096:5110, r5124:5125. Updates #1258.
Originally committed to SVN as r5126.
2011-01-05 14:00:46 +01:00
|
|
|
/// throw new agi::SomeException("Remember this is the wrong way!");
|
2009-08-05 22:51:32 +02:00
|
|
|
/// @endcode
|
|
|
|
/// Exceptions must not be allocated on heap, because of the risks of
|
|
|
|
/// leaking memory that way. (C++ FAQ Lite 17.8.)
|
|
|
|
///
|
|
|
|
/// When catching exceptions, make sure you catch them by reference,
|
|
|
|
/// otherwise polymorphism will not work. (The C++ Programming
|
|
|
|
/// Language Special Edition 14.2.1, C++ FAQ Lite 17.7.)
|
|
|
|
///
|
|
|
|
/// Catch like this:
|
|
|
|
/// @code
|
|
|
|
/// try {
|
|
|
|
/// /* ... */
|
|
|
|
/// }
|
Merge the dynamic menu, hotkey and toolbar branch to trunk. This doesn't include Windows support as vs2008 was being a major pain. This involves revisions r4921:4950, r4961:5002, r5005:5006, r5008:5056, r5062:5065, r5072, r5081:5082, r5087, r5096:5110, r5124:5125. Updates #1258.
Originally committed to SVN as r5126.
2011-01-05 14:00:46 +01:00
|
|
|
/// catch (agi::UserCancelException &e) {
|
2009-08-05 22:51:32 +02:00
|
|
|
/// /* handle the fact that the user cancelled */
|
|
|
|
/// }
|
Merge the dynamic menu, hotkey and toolbar branch to trunk. This doesn't include Windows support as vs2008 was being a major pain. This involves revisions r4921:4950, r4961:5002, r5005:5006, r5008:5056, r5062:5065, r5072, r5081:5082, r5087, r5096:5110, r5124:5125. Updates #1258.
Originally committed to SVN as r5126.
2011-01-05 14:00:46 +01:00
|
|
|
/// catch (agi::VideoInputException &e) {
|
2009-08-05 22:51:32 +02:00
|
|
|
/// /* handle the video provider failing */
|
|
|
|
/// }
|
|
|
|
/// @endcode
|
|
|
|
/// Don't always handle all exceptions the code you're protected might
|
|
|
|
/// throw, sometimes it's better to let an exception slip through and
|
|
|
|
/// let code further out handle it. Sometimes you might want to catch and
|
|
|
|
/// package an exception into something else, for example to represent
|
|
|
|
/// cases such as "subtitle file could not be read @e because the file
|
|
|
|
/// could not be opened for reading". This is the purpose of the "inner"
|
|
|
|
/// exceptions.
|
2009-07-22 02:10:36 +02:00
|
|
|
class Exception {
|
2009-08-05 22:51:32 +02:00
|
|
|
/// The error message
|
2010-05-21 03:13:36 +02:00
|
|
|
std::string message;
|
2009-07-30 06:24:23 +02:00
|
|
|
|
2009-07-22 02:10:36 +02:00
|
|
|
protected:
|
2009-08-05 22:51:32 +02:00
|
|
|
/// @brief Protected constructor initialising members
|
|
|
|
/// @param msg The error message
|
2009-07-30 06:24:23 +02:00
|
|
|
///
|
2009-08-05 22:51:32 +02:00
|
|
|
/// Deriving classes should always use this constructor for initialising
|
|
|
|
/// the base class.
|
2014-05-29 14:57:27 +02:00
|
|
|
Exception(std::string msg) : message(std::move(msg)) { }
|
2009-08-05 22:51:32 +02:00
|
|
|
|
2010-07-27 05:52:32 +02:00
|
|
|
public:
|
2009-08-05 22:51:32 +02:00
|
|
|
/// @brief Get the outer exception error message
|
|
|
|
/// @return Error message
|
2014-05-29 14:57:27 +02:00
|
|
|
std::string const& GetMessage() const { return message; }
|
2009-07-22 02:10:36 +02:00
|
|
|
};
|
|
|
|
|
2009-08-05 22:51:32 +02:00
|
|
|
/// @brief Convenience macro to include the current location in code
|
|
|
|
///
|
|
|
|
/// Intended for use in error messages where it can sometimes be convenient to
|
|
|
|
/// indicate the exact position the error occurred at.
|
2010-05-21 03:13:36 +02:00
|
|
|
#define AG_WHERE " (at " __FILE__ ":" #__LINE__ ")"
|
2009-07-22 02:10:36 +02:00
|
|
|
|
2014-05-29 14:57:27 +02:00
|
|
|
/// @brief Convenience macro for declaring exceptions
|
2009-08-05 22:51:32 +02:00
|
|
|
/// @param classname Name of the exception class to declare
|
|
|
|
/// @param baseclass Class to derive from
|
2014-05-29 14:57:27 +02:00
|
|
|
#define DEFINE_EXCEPTION(classname, baseclass) \
|
|
|
|
class classname : public baseclass { \
|
|
|
|
public: \
|
|
|
|
classname(std::string msg) : baseclass(std::move(msg)) { } \
|
|
|
|
}
|
2009-07-22 02:10:36 +02:00
|
|
|
|
Merge the dynamic menu, hotkey and toolbar branch to trunk. This doesn't include Windows support as vs2008 was being a major pain. This involves revisions r4921:4950, r4961:5002, r5005:5006, r5008:5056, r5062:5065, r5072, r5081:5082, r5087, r5096:5110, r5124:5125. Updates #1258.
Originally committed to SVN as r5126.
2011-01-05 14:00:46 +01:00
|
|
|
/// @class agi::UserCancelException
|
|
|
|
/// @extends agi::Exception
|
2009-08-05 22:51:32 +02:00
|
|
|
/// @brief Exception for "user cancel" events
|
|
|
|
///
|
|
|
|
/// I.e. when we want to abort an operation because the user requested that we do so.
|
|
|
|
/// Not actually an error and should not be handled as such.
|
|
|
|
///
|
|
|
|
/// This is intended to signal that an operation should be completely aborted at the
|
|
|
|
/// request of the user, and should usually be handled as close to the main UI as
|
|
|
|
/// possible, user cancel exceptions should unwind anything that was going on at the
|
|
|
|
/// moment. For this to work, RAII methodology has to be used consequently in the
|
|
|
|
/// code in question.
|
2014-05-29 14:57:27 +02:00
|
|
|
DEFINE_EXCEPTION(UserCancelException, Exception);
|
2009-07-22 02:10:36 +02:00
|
|
|
|
Merge the dynamic menu, hotkey and toolbar branch to trunk. This doesn't include Windows support as vs2008 was being a major pain. This involves revisions r4921:4950, r4961:5002, r5005:5006, r5008:5056, r5062:5065, r5072, r5081:5082, r5087, r5096:5110, r5124:5125. Updates #1258.
Originally committed to SVN as r5126.
2011-01-05 14:00:46 +01:00
|
|
|
/// @class agi::InternalError
|
|
|
|
/// @extends agi:Exception
|
2009-08-05 22:51:32 +02:00
|
|
|
/// @brief Errors that should never happen and point to some invalid assumption in the code
|
|
|
|
///
|
|
|
|
/// Throw an internal error when a sanity check fails, and the insanity should have
|
|
|
|
/// been caught and handled at an earlier stage, i.e. when something seems to
|
|
|
|
/// have become inconsistent. All internal errors are of the type "this should never
|
|
|
|
/// happen", most often you'll want this kind of error unwind all the way past the main UI
|
|
|
|
/// and eventually cause an abort().
|
2014-05-29 14:57:27 +02:00
|
|
|
DEFINE_EXCEPTION(InternalError, Exception);
|
2009-07-22 02:10:36 +02:00
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
/// @class agi::EnvironmentError
|
|
|
|
/// @extends agi:Exception
|
|
|
|
/// @brief The execution environment is broken in some fundamental way
|
2009-08-05 22:51:32 +02:00
|
|
|
///
|
2013-01-04 16:01:50 +01:00
|
|
|
/// Throw an environment error when a call to the platform API has failed
|
|
|
|
/// in some way that should normally never happen or suggests that the
|
|
|
|
/// runtime environment is too insane to support.
|
2014-05-29 14:57:27 +02:00
|
|
|
DEFINE_EXCEPTION(EnvironmentError, Exception);
|
2009-07-22 02:10:36 +02:00
|
|
|
|
Merge the dynamic menu, hotkey and toolbar branch to trunk. This doesn't include Windows support as vs2008 was being a major pain. This involves revisions r4921:4950, r4961:5002, r5005:5006, r5008:5056, r5062:5065, r5072, r5081:5082, r5087, r5096:5110, r5124:5125. Updates #1258.
Originally committed to SVN as r5126.
2011-01-05 14:00:46 +01:00
|
|
|
/// @class agi::InvalidInputException
|
|
|
|
/// @extends agi::Exception
|
2009-08-05 22:51:32 +02:00
|
|
|
/// @brief Some input data were invalid and could not be processed
|
2014-05-29 14:57:27 +02:00
|
|
|
DEFINE_EXCEPTION(InvalidInputException, Exception);
|
2010-06-06 01:44:07 +02:00
|
|
|
}
|