Remove a bunch of unused functionalty from agi::Exception

This commit is contained in:
Thomas Goyne 2014-05-29 05:57:27 -07:00
parent b43788fa7f
commit 8d26c66d0f
85 changed files with 239 additions and 359 deletions

View File

@ -57,7 +57,7 @@ int main(int argc, char **argv) {
try {
check(L, !LoadFile(L, argv[1]));
} catch (agi::Exception const& e) {
fprintf(stderr, "%s\n", e.GetChainedMessage().c_str());
fprintf(stderr, "%s\n", e.GetMessage().c_str());
}
for (int i = 2; i < argc; ++i)

View File

@ -37,15 +37,15 @@ icu::BreakIterator& get_break_iterator(const char *ptr, size_t len) {
std::call_once(token, [&] {
UErrorCode status = U_ZERO_ERROR;
bi.reset(BreakIterator::createCharacterInstance(Locale::getDefault(), status));
if (U_FAILURE(status)) throw agi::InternalError("Failed to create character iterator", nullptr);
if (U_FAILURE(status)) throw agi::InternalError("Failed to create character iterator");
});
UErrorCode err = U_ZERO_ERROR;
utext_ptr ut(utext_openUTF8(nullptr, ptr, len, &err));
if (U_FAILURE(err)) throw agi::InternalError("Failed to open utext", nullptr);
if (U_FAILURE(err)) throw agi::InternalError("Failed to open utext");
bi->setText(ut.get(), err);
if (U_FAILURE(err)) throw agi::InternalError("Failed to set break iterator text", nullptr);
if (U_FAILURE(err)) throw agi::InternalError("Failed to set break iterator text");
return *bi;
}

View File

@ -40,7 +40,7 @@ char *map(int64_t s_offset, uint64_t length, boost::interprocess::mode_t mode,
auto offset = static_cast<uint64_t>(s_offset);
if (offset + length > file_size)
throw agi::InternalError("Attempted to map beyond end of file", nullptr);
throw agi::InternalError("Attempted to map beyond end of file");
// Check if we can just use the current mapping
if (region && offset >= mapping_start && offset + length <= mapping_start + region->get_size())
@ -150,9 +150,9 @@ temp_file_mapping::temp_file_mapping(fs::path const& filename, uint64_t size)
unlink(filename.string().c_str());
if (ftruncate(handle, size) == -1) {
switch (errno) {
case EBADF: throw InternalError("Error opening file " + filename.string() + " not handled", nullptr);
case EBADF: throw InternalError("Error opening file " + filename.string() + " not handled");
case EFBIG: throw fs::DriveFull(filename);
case EINVAL: throw InternalError("File opened incorrectly: " + filename.string(), nullptr);
case EINVAL: throw InternalError("File opened incorrectly: " + filename.string());
case EROFS: throw fs::WriteDenied(filename);
default: throw fs::FileSystemUnknownError("Unknown error opening file: " + filename.string());
}

View File

@ -150,7 +150,7 @@ void ConfigVisitor::AddOptionValue(std::unique_ptr<OptionValue>&& opt) {
}
catch (agi::OptionValueError const& e) {
if (ignore_errors)
LOG_E("option/load/config_visitor") << "Error loading option from user configuration: " << e.GetChainedMessage();
LOG_E("option/load/config_visitor") << "Error loading option from user configuration: " << e.GetMessage();
else
throw;
}

View File

@ -25,10 +25,10 @@
namespace agi {
DEFINE_BASE_EXCEPTION_NOINNER(OptionJsonValueError, Exception)
DEFINE_SIMPLE_EXCEPTION_NOINNER(OptionJsonValueArray, OptionJsonValueError, "options/value/array")
DEFINE_SIMPLE_EXCEPTION_NOINNER(OptionJsonValueSingle, OptionJsonValueError, "options/value")
DEFINE_SIMPLE_EXCEPTION_NOINNER(OptionJsonValueNull, OptionJsonValueError, "options/value")
DEFINE_EXCEPTION(OptionJsonValueError, Exception);
DEFINE_EXCEPTION(OptionJsonValueArray, OptionJsonValueError);
DEFINE_EXCEPTION(OptionJsonValueSingle, OptionJsonValueError);
DEFINE_EXCEPTION(OptionJsonValueNull, OptionJsonValueError);
class ConfigVisitor final : public json::ConstVisitor {
/// Option map being populated

View File

@ -62,7 +62,7 @@ fs::path Path::Decode(std::string const& path) const {
fs::path Path::MakeRelative(fs::path const& path, std::string const& token) const {
const auto it = tokens.find(token);
if (it == tokens.end()) throw agi::InternalError("Bad token: " + token, nullptr);
if (it == tokens.end()) throw agi::InternalError("Bad token: " + token);
return MakeRelative(path, it->second);
}
@ -94,7 +94,7 @@ fs::path Path::MakeRelative(fs::path const& path, fs::path const& base) const {
fs::path Path::MakeAbsolute(fs::path path, std::string const& token) const {
if (path.empty()) return path;
const auto it = tokens.find(token);
if (it == tokens.end()) throw agi::InternalError("Bad token: " + token, nullptr);
if (it == tokens.end()) throw agi::InternalError("Bad token: " + token);
path.make_preferred();
const auto str = path.string();
@ -123,7 +123,7 @@ std::string Path::Encode(fs::path const& path) const {
void Path::SetToken(std::string const& token_name, fs::path const& token_value) {
const auto it = tokens.find(token_name);
if (it == tokens.end()) throw agi::InternalError("Bad token: " + token_name, nullptr);
if (it == tokens.end()) throw agi::InternalError("Bad token: " + token_name);
if (token_value.empty())
it->second = token_value;

View File

@ -26,8 +26,8 @@ namespace agi {
/// Character set conversion and detection.
namespace charset {
DEFINE_BASE_EXCEPTION_NOINNER(CharsetError, agi::Exception)
DEFINE_SIMPLE_EXCEPTION_NOINNER(UnknownCharset, CharsetError, "charset/unknown")
DEFINE_EXCEPTION(CharsetError, agi::Exception);
DEFINE_EXCEPTION(UnknownCharset, CharsetError);
/// List of detected encodings.
typedef std::vector<std::pair<float, std::string>> CharsetListDetected;

View File

@ -27,12 +27,12 @@
namespace agi {
namespace charset {
DEFINE_BASE_EXCEPTION_NOINNER(ConvError, Exception)
DEFINE_SIMPLE_EXCEPTION_NOINNER(UnsupportedConversion, ConvError, "iconv/unsupported")
DEFINE_SIMPLE_EXCEPTION_NOINNER(ConversionFailure, ConvError, "iconv/failed")
DEFINE_SIMPLE_EXCEPTION_NOINNER(BufferTooSmall, ConversionFailure, "iconv/failed/E2BIG")
DEFINE_SIMPLE_EXCEPTION_NOINNER(BadInput, ConversionFailure, "iconv/failed/EILSEQ")
DEFINE_SIMPLE_EXCEPTION_NOINNER(BadOutput, ConversionFailure, "iconv/failed/EINVAL")
DEFINE_EXCEPTION(ConvError, Exception);
DEFINE_EXCEPTION(UnsupportedConversion, ConvError);
DEFINE_EXCEPTION(ConversionFailure, ConvError);
DEFINE_EXCEPTION(BufferTooSmall, ConversionFailure);
DEFINE_EXCEPTION(BadInput, ConversionFailure);
DEFINE_EXCEPTION(BadOutput, ConversionFailure);
typedef void* iconv_t;

View File

@ -27,14 +27,8 @@
//
// Aegisub Project http://www.aegisub.org/
/// @file exception.h
/// @brief Base exception classes for structured error handling
/// @ingroup main_headers
///
#pragma once
#include <memory>
#include <string>
namespace agi {
@ -90,26 +84,13 @@ namespace agi {
/// The error message
std::string message;
/// An inner exception, the cause of this exception
std::shared_ptr<Exception> inner;
protected:
/// @brief Protected constructor initialising members
/// @param msg The error message
/// @param inr The inner exception, optional
///
/// Deriving classes should always use this constructor for initialising
/// the base class.
Exception(std::string msg, const Exception *inr = nullptr) : message(std::move(msg)) {
if (inr)
inner.reset(inr->Copy());
}
/// @brief Default constructor, not implemented
///
/// The default constructor is not implemented because it must not be used,
/// as it leaves the members un-initialised.
Exception();
Exception(std::string msg) : message(std::move(msg)) { }
public:
/// @brief Destructor
@ -117,41 +98,7 @@ namespace agi {
/// @brief Get the outer exception error message
/// @return Error message
virtual std::string GetMessage() const { return message; }
/// @brief Get error messages for chained exceptions
/// @return Chained error message
///
/// If there is an inner exception, prepend its chained error message to
/// our error message, with a CRLF between. Returns our own error message
/// alone if there is no inner exception.
std::string GetChainedMessage() const { if (inner.get()) return inner->GetChainedMessage() + "\r\n" + GetMessage(); else return GetMessage(); }
/// @brief Exception class printable name
///
/// Sub classes should implement this to return a constant character string
/// naming their exception in a hierarchic manner.
///
/// Exception classes inheriting directly from Exception define a top-level
/// name for their sub-tree, further sub-classes add further levels, each
/// level is separated by a slash. Characters allowed in the name for a
/// level are [a-z0-9_].
virtual const char * GetName() const = 0;
/// @brief Convert to char array as the error message
/// @return The error message
operator const char * () { return GetMessage().c_str(); }
/// @brief Convert to std::string as the error message
/// @return The error message
operator std::string () { return GetMessage(); }
/// @brief Create a copy of the exception allocated on the heap
/// @return A heap-allocated exception object
///
/// All deriving classes must implement this explicitly to avoid losing
/// information in the duplication.
virtual Exception *Copy() const = 0;
std::string const& GetMessage() const { return message; }
};
/// @brief Convenience macro to include the current location in code
@ -160,62 +107,14 @@ namespace agi {
/// indicate the exact position the error occurred at.
#define AG_WHERE " (at " __FILE__ ":" #__LINE__ ")"
/// @brief Convenience macro for declaring exceptions with no support for inner exception
/// @brief Convenience macro for declaring exceptions
/// @param classname Name of the exception class to declare
/// @param baseclass Class to derive from
/// @param displayname The printable name of the exception (return of GetName())
///
/// This macro covers most cases of exception classes where support for inner
/// exceptions is not relevant/wanted.
#define DEFINE_SIMPLE_EXCEPTION_NOINNER(classname,baseclass,displayname) \
class classname : public baseclass { \
public: \
classname(const std::string &msg) : baseclass(msg) { } \
const char * GetName() const { return displayname; } \
Exception * Copy() const { return new classname(*this); } \
};
/// @brief Convenience macro for declaring exceptions supporting inner exceptions
/// @param classname Name of the exception class to declare
/// @param baseclass Class to derive from
/// @param displayname The printable name of the exception (return of GetName())
///
/// This macro covers most cases of exception classes that should support
/// inner exceptions.
#define DEFINE_SIMPLE_EXCEPTION(classname,baseclass,displayname) \
class classname : public baseclass { \
public: \
classname(const std::string &msg, Exception *inner) : baseclass(msg, inner) { } \
const char * GetName() const { return displayname; } \
Exception * Copy() const { return new classname(*this); } \
};
/// @brief Macro for declaring non-instantiable exception base classes
/// @param classname Name of the exception class to declare
/// @param baseclass Class to derive from
///
/// Declares an exception class that does not implement the GetName() function
/// and as such (unless a base class implements it) is not constructable.
/// Classes declared by this macro do not support inner exceptions.
#define DEFINE_BASE_EXCEPTION_NOINNER(classname,baseclass) \
class classname : public baseclass { \
public: \
classname(const std::string &msg) : baseclass(msg) { } \
};
/// @brief Macro for declaring non-instantiable exception base classes with inner
/// exception support
/// @param classname Name of the exception class to declare
/// @param baseclass Class to derive from
///
/// Declares an exception class that does not implement the GetName() function
/// and as such (unless a base class implements it) is not constructable.
/// Classes declared by this macro do support inner exceptions.
#define DEFINE_BASE_EXCEPTION(classname,baseclass) \
class classname : public baseclass { \
public: \
classname(const std::string &msg, Exception *inner) : baseclass(msg, inner) { } \
};
#define DEFINE_EXCEPTION(classname, baseclass) \
class classname : public baseclass { \
public: \
classname(std::string msg) : baseclass(std::move(msg)) { } \
}
/// @class agi::UserCancelException
/// @extends agi::Exception
@ -229,7 +128,7 @@ namespace agi {
/// 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.
DEFINE_SIMPLE_EXCEPTION_NOINNER(UserCancelException,Exception,"nonerror/user_cancel")
DEFINE_EXCEPTION(UserCancelException, Exception);
/// @class agi::InternalError
/// @extends agi:Exception
@ -240,7 +139,7 @@ namespace agi {
/// 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().
DEFINE_SIMPLE_EXCEPTION(InternalError, Exception, "internal_error")
DEFINE_EXCEPTION(InternalError, Exception);
/// @class agi::EnvironmentError
/// @extends agi:Exception
@ -249,10 +148,10 @@ namespace agi {
/// 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.
DEFINE_SIMPLE_EXCEPTION_NOINNER(EnvironmentError, Exception, "environment_error")
DEFINE_EXCEPTION(EnvironmentError, Exception);
/// @class agi::InvalidInputException
/// @extends agi::Exception
/// @brief Some input data were invalid and could not be processed
DEFINE_BASE_EXCEPTION(InvalidInputException, Exception)
DEFINE_EXCEPTION(InvalidInputException, Exception);
}

View File

@ -44,7 +44,7 @@ namespace agi {
/// This base class can not be instantiated.
/// File system errors do not support inner exceptions, as they
/// are always originating causes for errors.
DEFINE_BASE_EXCEPTION_NOINNER(FileSystemError, Exception)
DEFINE_EXCEPTION(FileSystemError, Exception);
/// A file can't be accessed for some reason
DEFINE_FS_EXCEPTION(FileNotAccessible, FileSystemError, "File is not accessible: ");
@ -53,7 +53,7 @@ namespace agi {
DEFINE_FS_EXCEPTION(FileNotFound, FileNotAccessible, "File not found: ");
/// An error of some unknown type has occured
DEFINE_SIMPLE_EXCEPTION_NOINNER(FileSystemUnknownError, FileSystemError, "filesystem/unknown");
DEFINE_EXCEPTION(FileSystemUnknownError, FileSystemError);;
/// The path exists, but isn't a file
DEFINE_FS_EXCEPTION(NotAFile, FileNotAccessible, "Path is not a file (and should be): ");

View File

@ -26,8 +26,8 @@
namespace agi {
namespace io {
DEFINE_BASE_EXCEPTION_NOINNER(IOError, Exception)
DEFINE_SIMPLE_EXCEPTION_NOINNER(IOFatal, IOError, "io/fatal")
DEFINE_EXCEPTION(IOError, Exception);
DEFINE_EXCEPTION(IOFatal, IOError);
std::unique_ptr<std::istream> Open(fs::path const& file, bool binary = false);

View File

@ -12,10 +12,10 @@
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <vector>
#include <libaegisub/exception.h>
#include <libaegisub/fs_fwd.h>
#include "exception.h"
#include "fs_fwd.h"
#include <vector>
namespace agi {
namespace keyframe {
@ -29,6 +29,6 @@ namespace agi {
/// @param keyframes List of keyframes to save
void Save(agi::fs::path const& filename, std::vector<int> const& keyframes);
DEFINE_SIMPLE_EXCEPTION_NOINNER(Error, Exception, "keyframe/error")
DEFINE_EXCEPTION(Error, Exception);
}
}

View File

@ -79,7 +79,7 @@ int exception_wrapper(lua_State *L) {
return func(L);
}
catch (agi::Exception const& e) {
push_value(L, e.GetChainedMessage());
push_value(L, e.GetMessage());
return lua_error(L);
}
catch (std::exception const& e) {

View File

@ -27,9 +27,9 @@ namespace json {
namespace agi {
class Options;
DEFINE_BASE_EXCEPTION_NOINNER(MRUError,Exception)
DEFINE_SIMPLE_EXCEPTION_NOINNER(MRUErrorInvalidKey, MRUError, "mru/invalid")
DEFINE_SIMPLE_EXCEPTION_NOINNER(MRUErrorIndexOutOfRange, MRUError, "mru/invalid")
DEFINE_EXCEPTION(MRUError, Exception);
DEFINE_EXCEPTION(MRUErrorInvalidKey, MRUError);
DEFINE_EXCEPTION(MRUErrorIndexOutOfRange, MRUError);
/// @class MRUManager
/// @brief Most Recently Used (MRU) list handling

View File

@ -33,9 +33,9 @@ namespace json {
namespace agi {
DEFINE_BASE_EXCEPTION_NOINNER(OptionError,Exception)
DEFINE_SIMPLE_EXCEPTION_NOINNER(OptionErrorNotFound, OptionError, "options/not_found")
DEFINE_SIMPLE_EXCEPTION_NOINNER(OptionErrorDuplicateKey, OptionError, "options/dump/duplicate")
DEFINE_EXCEPTION(OptionError, Exception);
DEFINE_EXCEPTION(OptionErrorNotFound, OptionError);
DEFINE_EXCEPTION(OptionErrorDuplicateKey, OptionError);
class OptionValue;

View File

@ -27,8 +27,8 @@
#undef Bool
namespace agi {
DEFINE_BASE_EXCEPTION_NOINNER(OptionValueError, Exception)
DEFINE_SIMPLE_EXCEPTION_NOINNER(OptionValueErrorInvalidType, OptionValueError, "options/invalid_type")
DEFINE_EXCEPTION(OptionValueError, Exception);
DEFINE_EXCEPTION(OptionValueErrorInvalidType, OptionValueError);
/// Option type
/// No bitsets here.
@ -64,7 +64,7 @@ class OptionValue {
case OptionType::ListColor: return "List of Colors";
case OptionType::ListBool: return "List of Bools";
}
throw agi::InternalError("Invalid option type", nullptr);
throw agi::InternalError("Invalid option type");
}
OptionValueErrorInvalidType TypeError(OptionType type) const {

View File

@ -39,17 +39,17 @@ enum Time {
END
};
DEFINE_BASE_EXCEPTION_NOINNER(Error, Exception)
DEFINE_EXCEPTION(Error, Exception);
/// FPS specified is not a valid frame rate
DEFINE_SIMPLE_EXCEPTION_NOINNER(BadFPS, Error, "vfr/badfps")
DEFINE_EXCEPTION(BadFPS, Error);
/// Unknown timecode file format
DEFINE_SIMPLE_EXCEPTION_NOINNER(UnknownFormat, Error, "vfr/timecodes/unknownformat")
DEFINE_EXCEPTION(UnknownFormat, Error);
/// Invalid line encountered in a timecode file
DEFINE_SIMPLE_EXCEPTION_NOINNER(MalformedLine, Error, "vfr/timecodes/malformed")
DEFINE_EXCEPTION(MalformedLine, Error);
/// Timecode file or vector has too few timecodes to be usable
DEFINE_SIMPLE_EXCEPTION_NOINNER(TooFewTimecodes, Error, "vfr/timecodes/toofew")
DEFINE_EXCEPTION(TooFewTimecodes, Error);
/// Timecode file or vector has timecodes that are not monotonically increasing
DEFINE_SIMPLE_EXCEPTION_NOINNER(UnorderedTimecodes, Error, "vfr/timecodes/order")
DEFINE_EXCEPTION(UnorderedTimecodes, Error);
/// @class Framerate
/// @brief Class for managing everything related to converting frames to times

View File

@ -38,7 +38,7 @@ int wrap(lua_State *L) {
}
catch (agi::Exception const& e) {
lua_pushnil(L);
push_value(L, e.GetChainedMessage());
push_value(L, e.GetMessage());
return 2;
}
catch (error_tag) {

View File

@ -31,7 +31,7 @@ namespace agi { namespace lua {
filename = agi::fs::Canonicalize(raw_filename);
}
catch (agi::fs::FileSystemUnknownError const& e) {
LOG_E("auto4/lua") << "Error canonicalizing path: " << e.GetChainedMessage();
LOG_E("auto4/lua") << "Error canonicalizing path: " << e.GetMessage();
}
agi::read_file_mapping file(filename);
@ -112,7 +112,7 @@ namespace agi { namespace lua {
// Not an error so swallow and continue on
}
catch (agi::Exception const& e) {
return error(L, "Error loading Lua module \"%s\":\n%s", path.string().c_str(), e.GetChainedMessage().c_str());
return error(L, "Error loading Lua module \"%s\":\n%s", path.string().c_str(), e.GetMessage().c_str());
}
}

View File

@ -81,7 +81,7 @@ public:
agi::StringRange next_tok() {
if (pos.eof())
throw SubtitleFormatParseError("Failed parsing line: " + std::string(str.begin(), str.end()), nullptr);
throw SubtitleFormatParseError("Failed parsing line: " + std::string(str.begin(), str.end()));
return *pos++;
}
@ -100,7 +100,7 @@ void AssDialogue::Parse(std::string const& raw) {
str = agi::StringRange(raw.begin() + 9, raw.end());
}
else
throw SubtitleFormatParseError("Failed parsing line: " + raw, nullptr);
throw SubtitleFormatParseError("Failed parsing line: " + raw);
tokenizer tkn(str);

View File

@ -79,7 +79,7 @@ AssOverrideParameter::~AssOverrideParameter() {
}
template<> std::string AssOverrideParameter::Get<std::string>() const {
if (omitted) throw agi::InternalError("AssOverrideParameter::Get() called on omitted parameter", nullptr);
if (omitted) throw agi::InternalError("AssOverrideParameter::Get() called on omitted parameter");
if (block.get()) {
std::string str(block->GetText());
if (boost::starts_with(str, "{")) str.erase(begin(str));

View File

@ -146,7 +146,7 @@ void AssParser::ParseScriptInfoLine(std::string const& data) {
else if (version_str == "v4.00+")
version = 1;
else
throw SubtitleFormatParseError("Unknown SSA file format version", nullptr);
throw SubtitleFormatParseError("Unknown SSA file format version");
}
// Nothing actually supports the Collisions property and malformed values

View File

@ -56,7 +56,7 @@ class parser {
std::string next_tok() {
if (pos.eof())
throw SubtitleFormatParseError("Malformed style: not enough fields", nullptr);
throw SubtitleFormatParseError("Malformed style: not enough fields");
return agi::str(trim_copy(*pos++));
}
@ -69,7 +69,7 @@ public:
void check_done() const {
if (!pos.eof())
throw SubtitleFormatParseError("Malformed style: too many fields", nullptr);
throw SubtitleFormatParseError("Malformed style: too many fields");
}
std::string next_str() { return next_tok(); }
@ -80,7 +80,7 @@ public:
return boost::lexical_cast<int>(next_tok());
}
catch (boost::bad_lexical_cast const&) {
throw SubtitleFormatParseError("Malformed style: bad int field", nullptr);
throw SubtitleFormatParseError("Malformed style: bad int field");
}
}
@ -89,7 +89,7 @@ public:
return boost::lexical_cast<double>(next_tok());
}
catch (boost::bad_lexical_cast const&) {
throw SubtitleFormatParseError("Malformed style: bad double field", nullptr);
throw SubtitleFormatParseError("Malformed style: bad double field");
}
}

View File

@ -170,12 +170,12 @@ wxDEFINE_EVENT(EVT_VIDEO_ERROR, VideoProviderErrorEvent);
wxDEFINE_EVENT(EVT_SUBTITLES_ERROR, SubtitlesProviderErrorEvent);
VideoProviderErrorEvent::VideoProviderErrorEvent(VideoProviderError const& err)
: agi::Exception(err.GetMessage(), &err)
: agi::Exception(err.GetMessage())
{
SetEventType(EVT_VIDEO_ERROR);
}
SubtitlesProviderErrorEvent::SubtitlesProviderErrorEvent(std::string const& err)
: agi::Exception(err, nullptr)
: agi::Exception(err)
{
SetEventType(EVT_SUBTITLES_ERROR);
}

View File

@ -134,16 +134,12 @@ struct FrameReadyEvent final : public wxEvent {
// These exceptions are wxEvents so that they can be passed directly back to
// the parent thread as events
struct VideoProviderErrorEvent final : public wxEvent, public agi::Exception {
const char * GetName() const override { return "video/error"; }
wxEvent *Clone() const override { return new VideoProviderErrorEvent(*this); };
agi::Exception *Copy() const override { return new VideoProviderErrorEvent(*this); };
VideoProviderErrorEvent(VideoProviderError const& err);
};
struct SubtitlesProviderErrorEvent final : public wxEvent, public agi::Exception {
const char * GetName() const override { return "subtitles/error"; }
wxEvent *Clone() const override { return new SubtitlesProviderErrorEvent(*this); };
agi::Exception *Copy() const override { return new SubtitlesProviderErrorEvent(*this); };
SubtitlesProviderErrorEvent(std::string const& msg);
};

View File

@ -46,7 +46,7 @@ AudioColorScheme::AudioColorScheme(int prec, std::string const& scheme_name, int
case AudioStyle_Inactive: opt_base += "Inactive/"; break;
case AudioStyle_Selected: opt_base += "Selection/"; break;
case AudioStyle_Primary: opt_base += "Primary/"; break;
default: throw agi::InternalError("Unknown audio rendering styling", nullptr);
default: throw agi::InternalError("Unknown audio rendering styling");
}
double h_base = OPT_GET(opt_base + "Hue Offset")->GetDouble();

View File

@ -188,26 +188,26 @@ public:
namespace agi {
/// Base class for all audio-related errors
DEFINE_BASE_EXCEPTION(AudioError, Exception)
DEFINE_EXCEPTION(AudioError, Exception);
/// Opening the audio failed for any reason
DEFINE_SIMPLE_EXCEPTION(AudioOpenError, AudioError, "audio/open")
DEFINE_EXCEPTION(AudioOpenError, AudioError);
/// There are no audio providers available to open audio files
DEFINE_SIMPLE_EXCEPTION(NoAudioProvidersError, AudioOpenError, "audio/open/no_providers")
DEFINE_EXCEPTION(NoAudioProvidersError, AudioOpenError);
/// The file exists, but no providers could find any audio tracks in it
DEFINE_SIMPLE_EXCEPTION(AudioDataNotFoundError, AudioOpenError, "audio/open/no_tracks")
DEFINE_EXCEPTION(AudioDataNotFoundError, AudioOpenError);
/// There are audio tracks, but no provider could actually read them
DEFINE_SIMPLE_EXCEPTION(AudioProviderOpenError, AudioOpenError, "audio/open/provider")
DEFINE_EXCEPTION(AudioProviderOpenError, AudioOpenError);
/// The audio cache failed to initialize
DEFINE_SIMPLE_EXCEPTION(AudioCacheOpenError, AudioOpenError, "audio/open/cache")
DEFINE_EXCEPTION(AudioCacheOpenError, AudioOpenError);
/// There are no audio players available
DEFINE_SIMPLE_EXCEPTION(NoAudioPlayersError, AudioOpenError, "audio/open/no_players")
DEFINE_EXCEPTION(NoAudioPlayersError, AudioOpenError);
/// The audio player failed to initialize
DEFINE_SIMPLE_EXCEPTION(AudioPlayerOpenError, AudioOpenError, "audio/open/player")
DEFINE_EXCEPTION(AudioPlayerOpenError, AudioOpenError);
}

View File

@ -89,7 +89,7 @@ std::vector<std::string> AudioPlayerFactory::GetClasses() {
std::unique_ptr<AudioPlayer> AudioPlayerFactory::GetAudioPlayer(AudioProvider *provider, wxWindow *window) {
if (std::begin(factories) == std::end(factories))
throw agi::NoAudioPlayersError("No audio players are available.", nullptr);
throw agi::NoAudioPlayersError("No audio players are available.");
auto preferred = OPT_GET("Audio/Player")->GetString();
auto sorted = GetSorted(boost::make_iterator_range(std::begin(factories), std::end(factories)), preferred);
@ -100,8 +100,8 @@ std::unique_ptr<AudioPlayer> AudioPlayerFactory::GetAudioPlayer(AudioProvider *p
return factory->create(provider, window);
}
catch (agi::AudioPlayerOpenError const& err) {
error += std::string(factory->name) + " factory: " + err.GetChainedMessage() + "\n";
error += std::string(factory->name) + " factory: " + err.GetMessage() + "\n";
}
}
throw agi::AudioPlayerOpenError(error, nullptr);
throw agi::AudioPlayerOpenError(error);
}

View File

@ -295,7 +295,7 @@ AlsaPlayer::AlsaPlayer(AudioProvider *provider) try
{
}
catch (std::system_error const&) {
throw agi::AudioPlayerOpenError("AlsaPlayer: Creating the playback thread failed", 0);
throw agi::AudioPlayerOpenError("AlsaPlayer: Creating the playback thread failed");
}
AlsaPlayer::~AlsaPlayer()

View File

@ -102,7 +102,7 @@ DirectSoundPlayer::DirectSoundPlayer(AudioProvider *provider, wxWindow *parent)
// Initialize the DirectSound object
HRESULT res;
res = DirectSoundCreate8(&DSDEVID_DefaultPlayback,&directSound,nullptr); // TODO: support selecting audio device
if (FAILED(res)) throw agi::AudioPlayerOpenError("Failed initializing DirectSound", 0);
if (FAILED(res)) throw agi::AudioPlayerOpenError("Failed initializing DirectSound");
// Set DirectSound parameters
directSound->SetCooperativeLevel((HWND)parent->GetHandle(),DSSCL_PRIORITY);
@ -133,11 +133,11 @@ DirectSoundPlayer::DirectSoundPlayer(AudioProvider *provider, wxWindow *parent)
// Create the buffer
IDirectSoundBuffer *buf;
res = directSound->CreateSoundBuffer(&desc,&buf,nullptr);
if (res != DS_OK) throw agi::AudioPlayerOpenError("Failed creating DirectSound buffer", 0);
if (res != DS_OK) throw agi::AudioPlayerOpenError("Failed creating DirectSound buffer");
// Copy interface to buffer
res = buf->QueryInterface(IID_IDirectSoundBuffer8,(LPVOID*) &buffer);
if (res != S_OK) throw agi::AudioPlayerOpenError("Failed casting interface to IDirectSoundBuffer8", 0);
if (res != S_OK) throw agi::AudioPlayerOpenError("Failed casting interface to IDirectSoundBuffer8");
// Set data
offset = 0;

View File

@ -677,7 +677,7 @@ DirectSoundPlayer2Thread::DirectSoundPlayer2Thread(AudioProvider *provider, int
thread_handle = (HANDLE)_beginthreadex(0, 0, ThreadProc, this, 0, 0);
if (!thread_handle)
throw agi::AudioPlayerOpenError("Failed creating playback thread in DirectSoundPlayer2. This is bad.", 0);
throw agi::AudioPlayerOpenError("Failed creating playback thread in DirectSoundPlayer2. This is bad.");
HANDLE running_or_error[] = { thread_running, error_happened };
switch (WaitForMultipleObjects(2, running_or_error, FALSE, INFINITE))
@ -688,10 +688,10 @@ DirectSoundPlayer2Thread::DirectSoundPlayer2Thread(AudioProvider *provider, int
case WAIT_OBJECT_0 + 1:
// error happened, we fail
throw agi::AudioPlayerOpenError(error_message, 0);
throw agi::AudioPlayerOpenError(error_message);
default:
throw agi::AudioPlayerOpenError("Failed wait for thread start or thread error in DirectSoundPlayer2. This is bad.", 0);
throw agi::AudioPlayerOpenError("Failed wait for thread start or thread error in DirectSoundPlayer2. This is bad.");
}
}
@ -722,7 +722,7 @@ void DirectSoundPlayer2Thread::Play(int64_t start, int64_t count)
case WAIT_OBJECT_0+1: // Error
throw error_message;
default:
throw agi::InternalError("Unexpected result from WaitForMultipleObjects in DirectSoundPlayer2Thread::Play", 0);
throw agi::InternalError("Unexpected result from WaitForMultipleObjects in DirectSoundPlayer2Thread::Play");
}
}
@ -820,7 +820,7 @@ DirectSoundPlayer2::DirectSoundPlayer2(AudioProvider *provider, wxWindow *parent
catch (const char *msg)
{
LOG_E("audio/player/dsound") << msg;
throw agi::AudioPlayerOpenError(msg, 0);
throw agi::AudioPlayerOpenError(msg);
}
}

View File

@ -61,7 +61,7 @@
#pragma comment(lib, "openal32.lib")
#endif
DEFINE_SIMPLE_EXCEPTION(OpenALException, agi::AudioPlayerOpenError, "audio/open/player/openal")
DEFINE_EXCEPTION(OpenALException, agi::AudioPlayerOpenError);
namespace {
class OpenALPlayer final : public AudioPlayer, wxTimer {
@ -130,25 +130,25 @@ OpenALPlayer::OpenALPlayer(AudioProvider *provider)
try {
// Open device
device = alcOpenDevice(nullptr);
if (!device) throw OpenALException("Failed opening default OpenAL device", nullptr);
if (!device) throw OpenALException("Failed opening default OpenAL device");
// Create context
context = alcCreateContext(device, nullptr);
if (!context) throw OpenALException("Failed creating OpenAL context", nullptr);
if (!alcMakeContextCurrent(context)) throw OpenALException("Failed selecting OpenAL context", nullptr);
if (!context) throw OpenALException("Failed creating OpenAL context");
if (!alcMakeContextCurrent(context)) throw OpenALException("Failed selecting OpenAL context");
// Clear error code
alGetError();
// Generate buffers
alGenBuffers(num_buffers, buffers);
if (alGetError() != AL_NO_ERROR) throw OpenALException("Error generating OpenAL buffers", nullptr);
if (alGetError() != AL_NO_ERROR) throw OpenALException("Error generating OpenAL buffers");
// Generate source
alGenSources(1, &source);
if (alGetError() != AL_NO_ERROR) {
alDeleteBuffers(num_buffers, buffers);
throw OpenALException("Error generating OpenAL source", nullptr);
throw OpenALException("Error generating OpenAL source");
}
}
catch (...)

View File

@ -54,7 +54,7 @@
#endif
namespace {
DEFINE_SIMPLE_EXCEPTION(OSSError, agi::AudioPlayerOpenError, "audio/player/open/oss")
DEFINE_EXCEPTION(OSSError, agi::AudioPlayerOpenError);
class OSSPlayerThread;
class OSSPlayer final : public AudioPlayer {
@ -153,7 +153,7 @@ void OSSPlayer::OpenStream()
wxString device = to_wx(OPT_GET("Player/Audio/OSS/Device")->GetString());
dspdev = ::open(device.utf8_str(), O_WRONLY, 0);
if (dspdev < 0) {
throw OSSError("OSS player: opening device failed", 0);
throw OSSError("OSS player: opening device failed");
}
// Use a reasonable buffer policy for low latency (OSS4)
@ -165,7 +165,7 @@ void OSSPlayer::OpenStream()
// Set number of channels
int channels = provider->GetChannels();
if (ioctl(dspdev, SNDCTL_DSP_CHANNELS, &channels) < 0) {
throw OSSError("OSS player: setting channels failed", 0);
throw OSSError("OSS player: setting channels failed");
}
// Set sample format
@ -178,17 +178,17 @@ void OSSPlayer::OpenStream()
sample_format = AFMT_S16_LE;
break;
default:
throw OSSError("OSS player: can only handle 8 and 16 bit sound", 0);
throw OSSError("OSS player: can only handle 8 and 16 bit sound");
}
if (ioctl(dspdev, SNDCTL_DSP_SETFMT, &sample_format) < 0) {
throw OSSError("OSS player: setting sample format failed", 0);
throw OSSError("OSS player: setting sample format failed");
}
// Set sample rate
rate = provider->GetSampleRate();
if (ioctl(dspdev, SNDCTL_DSP_SPEED, &rate) < 0) {
throw OSSError("OSS player: setting samplerate failed", 0);
throw OSSError("OSS player: setting samplerate failed");
}
}

View File

@ -44,7 +44,7 @@
#include <libaegisub/log.h>
#include <libaegisub/make_unique.h>
DEFINE_SIMPLE_EXCEPTION(PortAudioError, agi::AudioPlayerOpenError, "audio/player/open/portaudio")
DEFINE_EXCEPTION(PortAudioError, agi::AudioPlayerOpenError);
// Uncomment to enable extremely spammy debug logging
//#define PORTAUDIO_DEBUG

View File

@ -101,7 +101,7 @@ PulseAudioPlayer::PulseAudioPlayer(AudioProvider *provider) : AudioPlayer(provid
// Initialise a mainloop
mainloop = pa_threaded_mainloop_new();
if (!mainloop)
throw agi::AudioPlayerOpenError("Failed to initialise PulseAudio threaded mainloop object", 0);
throw agi::AudioPlayerOpenError("Failed to initialise PulseAudio threaded mainloop object");
pa_threaded_mainloop_start(mainloop);
@ -109,7 +109,7 @@ PulseAudioPlayer::PulseAudioPlayer(AudioProvider *provider) : AudioPlayer(provid
context = pa_context_new(pa_threaded_mainloop_get_api(mainloop), "Aegisub");
if (!context) {
pa_threaded_mainloop_free(mainloop);
throw agi::AudioPlayerOpenError("Failed to create PulseAudio context", 0);
throw agi::AudioPlayerOpenError("Failed to create PulseAudio context");
}
pa_context_set_state_callback(context, (pa_context_notify_cb_t)pa_context_notify, this);
@ -127,7 +127,7 @@ PulseAudioPlayer::PulseAudioPlayer(AudioProvider *provider) : AudioPlayer(provid
pa_context_unref(context);
pa_threaded_mainloop_stop(mainloop);
pa_threaded_mainloop_free(mainloop);
throw agi::AudioPlayerOpenError(std::string("PulseAudio reported error: ") + pa_strerror(paerror), 0);
throw agi::AudioPlayerOpenError(std::string("PulseAudio reported error: ") + pa_strerror(paerror));
}
// otherwise loop once more
}
@ -148,7 +148,7 @@ PulseAudioPlayer::PulseAudioPlayer(AudioProvider *provider) : AudioPlayer(provid
pa_context_unref(context);
pa_threaded_mainloop_stop(mainloop);
pa_threaded_mainloop_free(mainloop);
throw agi::AudioPlayerOpenError("PulseAudio could not create stream", 0);
throw agi::AudioPlayerOpenError("PulseAudio could not create stream");
}
pa_stream_set_state_callback(stream, (pa_stream_notify_cb_t)pa_stream_notify, this);
pa_stream_set_write_callback(stream, (pa_stream_request_cb_t)pa_stream_write, this);
@ -157,7 +157,7 @@ PulseAudioPlayer::PulseAudioPlayer(AudioProvider *provider) : AudioPlayer(provid
paerror = pa_stream_connect_playback(stream, nullptr, nullptr, (pa_stream_flags_t)(PA_STREAM_INTERPOLATE_TIMING|PA_STREAM_NOT_MONOTONOUS|PA_STREAM_AUTO_TIMING_UPDATE), nullptr, nullptr);
if (paerror) {
LOG_E("audio/player/pulse") << "Stream connection failed: " << pa_strerror(paerror) << "(" << paerror << ")";
throw agi::AudioPlayerOpenError(std::string("PulseAudio reported error: ") + pa_strerror(paerror), 0);
throw agi::AudioPlayerOpenError(std::string("PulseAudio reported error: ") + pa_strerror(paerror));
}
while (true) {
stream_notify.Wait();
@ -166,7 +166,7 @@ PulseAudioPlayer::PulseAudioPlayer(AudioProvider *provider) : AudioPlayer(provid
} else if (sstate == PA_STREAM_FAILED) {
paerror = pa_context_errno(context);
LOG_E("audio/player/pulse") << "Stream connection failed: " << pa_strerror(paerror) << "(" << paerror << ")";
throw agi::AudioPlayerOpenError("PulseAudio player: Something went wrong connecting the stream", 0);
throw agi::AudioPlayerOpenError("PulseAudio player: Something went wrong connecting the stream");
}
}
}

View File

@ -44,7 +44,7 @@ void AudioProvider::GetAudioWithVolume(void *buf, int64_t start, int64_t count,
if (volume == 1.0) return;
if (bytes_per_sample != 2)
throw agi::InternalError("GetAudioWithVolume called on unconverted audio stream", nullptr);
throw agi::InternalError("GetAudioWithVolume called on unconverted audio stream");
short *buffer = static_cast<int16_t *>(buf);
for (size_t i = 0; i < (size_t)count; ++i)
@ -80,7 +80,7 @@ void AudioProvider::GetAudio(void *buf, int64_t start, int64_t count) const {
FillBuffer(buf, start, count);
}
catch (AudioDecodeError const& e) {
LOG_E("audio_provider") << e.GetChainedMessage();
LOG_E("audio_provider") << e.GetMessage();
ZeroFill(buf, count);
return;
}
@ -144,19 +144,19 @@ std::unique_ptr<AudioProvider> AudioProviderFactory::GetProvider(agi::fs::path c
break;
}
catch (agi::fs::FileNotFound const& err) {
LOG_D("audio_provider") << err.GetChainedMessage();
LOG_D("audio_provider") << err.GetMessage();
msg_all += std::string(factory->name) + ": " + err.GetMessage() + " not found.\n";
}
catch (agi::AudioDataNotFoundError const& err) {
LOG_D("audio_provider") << err.GetChainedMessage();
LOG_D("audio_provider") << err.GetMessage();
found_file = true;
msg_all += std::string(factory->name) + ": " + err.GetChainedMessage() + "\n";
msg_all += std::string(factory->name) + ": " + err.GetMessage() + "\n";
}
catch (agi::AudioOpenError const& err) {
LOG_D("audio_provider") << err.GetChainedMessage();
LOG_D("audio_provider") << err.GetMessage();
found_audio = true;
found_file = true;
std::string thismsg = std::string(factory->name) + ": " + err.GetChainedMessage() + "\n";
std::string thismsg = std::string(factory->name) + ": " + err.GetMessage() + "\n";
msg_all += thismsg;
msg_partial += thismsg;
}
@ -164,9 +164,9 @@ std::unique_ptr<AudioProvider> AudioProviderFactory::GetProvider(agi::fs::path c
if (!provider) {
if (found_audio)
throw agi::AudioProviderOpenError(msg_partial, nullptr);
throw agi::AudioProviderOpenError(msg_partial);
if (found_file)
throw agi::AudioDataNotFoundError(msg_all, nullptr);
throw agi::AudioDataNotFoundError(msg_all);
throw agi::fs::FileNotFound(filename);
}
@ -187,5 +187,5 @@ std::unique_ptr<AudioProvider> AudioProviderFactory::GetProvider(agi::fs::path c
// Convert to HD
if (cache == 2) return CreateHDAudioProvider(std::move(provider));
throw agi::AudioCacheOpenError("Unknown caching method", nullptr);
throw agi::AudioCacheOpenError("Unknown caching method");
}

View File

@ -89,22 +89,22 @@ AvisynthAudioProvider::AvisynthAudioProvider(agi::fs::path const& filename) {
LoadFromClip(env->Invoke("DirectShowSource", AVSValue(args, 3), argnames));
// Otherwise fail
else
throw agi::AudioProviderOpenError("No suitable audio source filter found. Try placing DirectShowSource.dll in the Aegisub application directory.", 0);
throw agi::AudioProviderOpenError("No suitable audio source filter found. Try placing DirectShowSource.dll in the Aegisub application directory.");
}
}
catch (AvisynthError &err) {
std::string errmsg(err.msg);
if (errmsg.find("filter graph manager won't talk to me") != errmsg.npos)
throw agi::AudioDataNotFoundError("Avisynth error: " + errmsg, 0);
throw agi::AudioDataNotFoundError("Avisynth error: " + errmsg);
else
throw agi::AudioProviderOpenError("Avisynth error: " + errmsg, 0);
throw agi::AudioProviderOpenError("Avisynth error: " + errmsg);
}
}
void AvisynthAudioProvider::LoadFromClip(AVSValue clip) {
// Check if it has audio
VideoInfo vi = clip.AsClip()->GetVideoInfo();
if (!vi.HasAudio()) throw agi::AudioDataNotFoundError("No audio found.", 0);
if (!vi.HasAudio()) throw agi::AudioDataNotFoundError("No audio found.");
IScriptEnvironment *env = avs_wrapper.GetEnv();

View File

@ -35,7 +35,7 @@ class BitdepthConvertAudioProvider final : public AudioProviderWrapper {
public:
BitdepthConvertAudioProvider(std::unique_ptr<AudioProvider> src) : AudioProviderWrapper(std::move(src)) {
if (bytes_per_sample > 8)
throw agi::AudioProviderOpenError("Audio format converter: audio with bitdepths greater than 64 bits/sample is currently unsupported", nullptr);
throw agi::AudioProviderOpenError("Audio format converter: audio with bitdepths greater than 64 bits/sample is currently unsupported");
src_bytes_per_sample = bytes_per_sample;
bytes_per_sample = sizeof(Target);
@ -107,9 +107,9 @@ class DownmixAudioProvider final : public AudioProviderWrapper {
public:
DownmixAudioProvider(std::unique_ptr<AudioProvider> src) : AudioProviderWrapper(std::move(src)) {
if (bytes_per_sample != 2)
throw agi::InternalError("DownmixAudioProvider requires 16-bit input", nullptr);
throw agi::InternalError("DownmixAudioProvider requires 16-bit input");
if (channels == 1)
throw agi::InternalError("DownmixAudioProvider requires multi-channel input", nullptr);
throw agi::InternalError("DownmixAudioProvider requires multi-channel input");
src_channels = channels;
channels = 1;
}
@ -137,9 +137,9 @@ class SampleDoublingAudioProvider final : public AudioProviderWrapper {
public:
SampleDoublingAudioProvider(std::unique_ptr<AudioProvider> src) : AudioProviderWrapper(std::move(src)) {
if (source->GetBytesPerSample() != 2)
throw agi::InternalError("UpsampleAudioProvider requires 16-bit input", nullptr);
throw agi::InternalError("UpsampleAudioProvider requires 16-bit input");
if (source->GetChannels() != 1)
throw agi::InternalError("UpsampleAudioProvider requires mono input", nullptr);
throw agi::InternalError("UpsampleAudioProvider requires mono input");
sample_rate *= 2;
num_samples *= 2;

View File

@ -79,10 +79,10 @@ FFmpegSourceAudioProvider::FFmpegSourceAudioProvider(agi::fs::path const& filena
LoadAudio(filename);
}
catch (std::string const& err) {
throw agi::AudioProviderOpenError(err, nullptr);
throw agi::AudioProviderOpenError(err);
}
catch (const char *err) {
throw agi::AudioProviderOpenError(err, nullptr);
throw agi::AudioProviderOpenError(err);
}
void FFmpegSourceAudioProvider::LoadAudio(agi::fs::path const& filename) {
@ -91,12 +91,12 @@ void FFmpegSourceAudioProvider::LoadAudio(agi::fs::path const& filename) {
if (ErrInfo.SubType == FFMS_ERROR_FILE_READ)
throw agi::fs::FileNotFound(std::string(ErrInfo.Buffer));
else
throw agi::AudioDataNotFoundError(ErrInfo.Buffer, nullptr);
throw agi::AudioDataNotFoundError(ErrInfo.Buffer);
}
std::map<int, std::string> TrackList = GetTracksOfType(Indexer, FFMS_TYPE_AUDIO);
if (TrackList.empty())
throw agi::AudioDataNotFoundError("no audio tracks found", nullptr);
throw agi::AudioDataNotFoundError("no audio tracks found");
// initialize the track number to an invalid value so we can detect later on
// whether the user actually had to choose a track or not
@ -124,7 +124,7 @@ void FFmpegSourceAudioProvider::LoadAudio(agi::fs::path const& filename) {
if (TrackNumber < 0)
TrackNumber = FFMS_GetFirstTrackOfType(Index, FFMS_TYPE_AUDIO, &ErrInfo);
if (TrackNumber < 0)
throw agi::AudioDataNotFoundError(std::string("Couldn't find any audio tracks: ") + ErrInfo.Buffer, nullptr);
throw agi::AudioDataNotFoundError(std::string("Couldn't find any audio tracks: ") + ErrInfo.Buffer);
// index is valid and track number is now set,
// but do we have indexing info for the desired audio track?
@ -166,7 +166,7 @@ void FFmpegSourceAudioProvider::LoadAudio(agi::fs::path const& filename) {
AudioSource = FFMS_CreateAudioSource(filename.string().c_str(), TrackNumber, Index, -1, &ErrInfo);