mirror of https://github.com/odrling/Aegisub
Throw only real exceptions from subtitle io stuff
This commit is contained in:
parent
78b70e987e
commit
ff6394c95e
|
@ -46,6 +46,8 @@
|
|||
|
||||
#include "ass_dialogue.h"
|
||||
#include "ass_override.h"
|
||||
#include "compat.h"
|
||||
#include "subtitle_format.h"
|
||||
#include "utils.h"
|
||||
|
||||
AssDialogue::AssDialogue()
|
||||
|
@ -82,7 +84,7 @@ AssDialogue::AssDialogue(wxString const& data)
|
|||
, Style("Default")
|
||||
{
|
||||
if (!Parse(data))
|
||||
throw "Failed parsing line.";
|
||||
throw SubtitleFormatParseError(STD_STR("Failed parsing line: " + data), 0);
|
||||
}
|
||||
|
||||
AssDialogue::~AssDialogue () {
|
||||
|
|
|
@ -79,11 +79,9 @@ AssFile::~AssFile() {
|
|||
|
||||
/// @brief Load generic subs
|
||||
void AssFile::Load(const wxString &_filename, wxString const& charset) {
|
||||
try {
|
||||
// Get proper format reader
|
||||
const SubtitleFormat *reader = SubtitleFormat::GetReader(_filename);
|
||||
if (!reader) throw "Unknown file type";
|
||||
|
||||
try {
|
||||
AssFile temp;
|
||||
reader->ReadFile(&temp, _filename, charset);
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "ass_dialogue.h"
|
||||
#include "ass_file.h"
|
||||
#include "ass_style.h"
|
||||
#include "subtitle_format.h"
|
||||
|
||||
#ifndef AGI_PRE
|
||||
#include <wx/log.h>
|
||||
|
@ -83,7 +84,7 @@ void AssParser::ParseScriptInfoLine(wxString const& data) {
|
|||
else if (versionString == "v4.00+")
|
||||
trueVersion = 1;
|
||||
else
|
||||
throw "Unknown SSA file format version";
|
||||
throw SubtitleFormatParseError("Unknown SSA file format version", 0);
|
||||
if (trueVersion != version) {
|
||||
wxLogMessage("Warning: File has the wrong extension.");
|
||||
version = trueVersion;
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
#endif
|
||||
|
||||
#include "ass_style.h"
|
||||
#include "subtitle_format.h"
|
||||
#include "utils.h"
|
||||
|
||||
AssColor::AssColor () {
|
||||
|
@ -172,21 +173,21 @@ AssStyle::AssStyle()
|
|||
}
|
||||
|
||||
static wxString get_next_string(wxStringTokenizer &tok) {
|
||||
if (!tok.HasMoreTokens()) throw "Malformed style: not enough fields";
|
||||
if (!tok.HasMoreTokens()) throw SubtitleFormatParseError("Malformed style: not enough fields", 0);
|
||||
return tok.GetNextToken();
|
||||
}
|
||||
|
||||
static int get_next_int(wxStringTokenizer &tok) {
|
||||
long temp;
|
||||
if (!get_next_string(tok).ToLong(&temp))
|
||||
throw "Malformed style: could not parse int field";
|
||||
throw SubtitleFormatParseError("Malformed style: could not parse int field", 0);
|
||||
return temp;
|
||||
}
|
||||
|
||||
static double get_next_double(wxStringTokenizer &tok) {
|
||||
double temp;
|
||||
if (!get_next_string(tok).ToDouble(&temp))
|
||||
throw "Malformed style: could not parse double field";
|
||||
throw SubtitleFormatParseError("Malformed style: could not parse double field", 0);
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
@ -265,7 +266,7 @@ AssStyle::AssStyle(wxString rawData, int version)
|
|||
encoding = get_next_int(tkn);
|
||||
|
||||
if (tkn.HasMoreTokens())
|
||||
throw "Malformed style: too many fields";
|
||||
throw SubtitleFormatParseError("Malformed style: too many fields", 0);
|
||||
|
||||
UpdateData();
|
||||
}
|
||||
|
|
|
@ -600,14 +600,6 @@ void DialogStyleManager::OnCurrentImport() {
|
|||
try {
|
||||
temp.Load(filename);
|
||||
}
|
||||
catch (const char *err) {
|
||||
wxMessageBox(err, "Error", wxOK | wxICON_ERROR | wxCENTER, this);
|
||||
return;
|
||||
}
|
||||
catch (wxString const& err) {
|
||||
wxMessageBox(err, "Error", wxOK | wxICON_ERROR | wxCENTER, this);
|
||||
return;
|
||||
}
|
||||
catch (agi::Exception const& err) {
|
||||
wxMessageBox(lagi_wxString(err.GetChainedMessage()), "Error", wxOK | wxICON_ERROR | wxCENTER, this);
|
||||
}
|
||||
|
|
|
@ -455,14 +455,6 @@ void FrameMain::LoadSubtitles(wxString const& filename, wxString const& charset)
|
|||
config::mru->Remove("Subtitle", STD_STR(filename));
|
||||
return;
|
||||
}
|
||||
catch (const char *err) {
|
||||
wxMessageBox(err, "Error", wxOK | wxICON_ERROR | wxCENTER, this);
|
||||
return;
|
||||
}
|
||||
catch (wxString const& err) {
|
||||
wxMessageBox(err, "Error", wxOK | wxICON_ERROR | wxCENTER, this);
|
||||
return;
|
||||
}
|
||||
catch (agi::Exception const& err) {
|
||||
wxMessageBox(lagi_wxString(err.GetChainedMessage()), "Error", wxOK | wxICON_ERROR | wxCENTER, this);
|
||||
}
|
||||
|
|
|
@ -331,21 +331,21 @@ void SubtitleFormat::DestroyFormats() {
|
|||
}
|
||||
|
||||
template<class Cont, class Pred>
|
||||
SubtitleFormat *find_or_null(Cont &container, Pred pred) {
|
||||
SubtitleFormat *find_or_throw(Cont &container, Pred pred) {
|
||||
typename Cont::iterator it = find_if(container.begin(), container.end(), pred);
|
||||
if (it == container.end())
|
||||
return 0;
|
||||
throw UnknownSubtitleFormatError("Subtitle format for extension not found", 0);
|
||||
return *it;
|
||||
}
|
||||
|
||||
const SubtitleFormat *SubtitleFormat::GetReader(wxString const& filename) {
|
||||
LoadFormats();
|
||||
return find_or_null(formats, bind(&SubtitleFormat::CanReadFile, _1, filename));
|
||||
return find_or_throw(formats, bind(&SubtitleFormat::CanReadFile, _1, filename));
|
||||
}
|
||||
|
||||
const SubtitleFormat *SubtitleFormat::GetWriter(wxString const& filename) {
|
||||
LoadFormats();
|
||||
return find_or_null(formats, bind(&SubtitleFormat::CanWriteFile, _1, filename));
|
||||
return find_or_throw(formats, bind(&SubtitleFormat::CanWriteFile, _1, filename));
|
||||
}
|
||||
|
||||
wxString SubtitleFormat::GetWildcards(int mode) {
|
||||
|
|
|
@ -146,3 +146,4 @@ public:
|
|||
};
|
||||
|
||||
DEFINE_SIMPLE_EXCEPTION(SubtitleFormatParseError, agi::InvalidInputException, "subtitle_io/parse/generic")
|
||||
DEFINE_SIMPLE_EXCEPTION(UnknownSubtitleFormatError, agi::InvalidInputException, "subtitle_io/unknown")
|
||||
|
|
Loading…
Reference in New Issue