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