Eliminate all remaining places where strings are thrown as exceptions

Closes #916.
This commit is contained in:
Thomas Goyne 2014-06-10 15:28:45 -07:00
parent 789ff25f27
commit 7de5fbac92
15 changed files with 29 additions and 73 deletions

View file

@ -67,8 +67,7 @@ void AssExporter::DrawSettings(wxWindow *parent, wxSizer *target_sizer) {
void AssExporter::AddFilter(std::string const& name) { void AssExporter::AddFilter(std::string const& name) {
auto filter = AssExportFilterChain::GetFilter(name); auto filter = AssExportFilterChain::GetFilter(name);
if (!filter) throw agi::InternalError("Filter not found: " + name);
if (!filter) throw "Filter not found: " + name;
filters.push_back(filter); filters.push_back(filter);
} }
@ -90,7 +89,7 @@ void AssExporter::Export(agi::fs::path const& filename, std::string const& chars
const SubtitleFormat *writer = SubtitleFormat::GetWriter(filename); const SubtitleFormat *writer = SubtitleFormat::GetWriter(filename);
if (!writer) if (!writer)
throw "Unknown file type."; throw agi::InvalidInputException("Unknown file type.");
writer->WriteFile(&subs, filename, c->project->Timecodes(), charset); writer->WriteFile(&subs, filename, c->project->Timecodes(), charset);
} }
@ -104,5 +103,5 @@ std::string const& AssExporter::GetDescription(std::string const& name) const {
auto filter = AssExportFilterChain::GetFilter(name); auto filter = AssExportFilterChain::GetFilter(name);
if (filter) if (filter)
return filter->GetDescription(); return filter->GetDescription();
throw "Filter not found: " + name; throw agi::InternalError("Filter not found: " + name);
} }

View file

@ -58,7 +58,7 @@ std::shared_ptr<VideoFrame> AsyncVideoProvider::ProcFrame(int frame_number, doub
} }
} }
} }
catch (std::string const& err) { throw SubtitlesProviderErrorEvent(err); } catch (agi::Exception const& err) { throw SubtitlesProviderErrorEvent(err.GetMessage()); }
try { try {
subs_provider->DrawSubtitles(*frame, time / 1000.); subs_provider->DrawSubtitles(*frame, time / 1000.);
@ -72,8 +72,8 @@ static std::unique_ptr<SubtitlesProvider> get_subs_provider(wxEvtHandler *evt_ha
try { try {
return SubtitlesProviderFactory::GetProvider(br); return SubtitlesProviderFactory::GetProvider(br);
} }
catch (std::string const& err) { catch (agi::Exception const& err) {
evt_handler->AddPendingEvent(SubtitlesProviderErrorEvent(err)); evt_handler->AddPendingEvent(SubtitlesProviderErrorEvent(err.GetMessage()));
return nullptr; return nullptr;
} }
} }

View file

@ -78,11 +78,8 @@ FFmpegSourceAudioProvider::FFmpegSourceAudioProvider(agi::fs::path const& filena
LoadAudio(filename); LoadAudio(filename);
} }
catch (std::string const& err) { catch (agi::EnvironmentError const& err) {
throw agi::AudioProviderOpenError(err); throw agi::AudioProviderOpenError(err.GetMessage());
}
catch (const char *err) {
throw agi::AudioProviderOpenError(err);
} }
void FFmpegSourceAudioProvider::LoadAudio(agi::fs::path const& filename) { void FFmpegSourceAudioProvider::LoadAudio(agi::fs::path const& filename) {

View file

@ -322,9 +322,6 @@ static void save_subtitles(agi::Context *c, agi::fs::path filename) {
catch (const agi::Exception& err) { catch (const agi::Exception& err) {
wxMessageBox(to_wx(err.GetMessage()), "Error", wxOK | wxICON_ERROR | wxCENTER, c->parent); wxMessageBox(to_wx(err.GetMessage()), "Error", wxOK | wxICON_ERROR | wxCENTER, c->parent);
} }
catch (const char *err) {
wxMessageBox(err, "Error", wxOK | wxICON_ERROR | wxCENTER, c->parent);
}
catch (...) { catch (...) {
wxMessageBox("Unknown error", "Error", wxOK | wxICON_ERROR | wxCENTER, c->parent); wxMessageBox("Unknown error", "Error", wxOK | wxICON_ERROR | wxCENTER, c->parent);
} }

View file

@ -199,14 +199,7 @@ void DialogExport::OnProcess(wxCommandEvent &) {
c->ass->Properties.export_encoding = from_wx(charset_list->GetStringSelection()); c->ass->Properties.export_encoding = from_wx(charset_list->GetStringSelection());
exporter.Export(filename, from_wx(charset_list->GetStringSelection()), &d); exporter.Export(filename, from_wx(charset_list->GetStringSelection()), &d);
} }
catch (agi::UserCancelException const&) { catch (agi::UserCancelException const&) { }
}
catch (const char *error) {
wxMessageBox(error, "Error exporting subtitles", wxOK | wxICON_ERROR | wxCENTER, &d);
}
catch (wxString const& error) {
wxMessageBox(error, "Error exporting subtitles", wxOK | wxICON_ERROR | wxCENTER, &d);
}
catch (agi::Exception const& err) { catch (agi::Exception const& err) {
wxMessageBox(to_wx(err.GetMessage()), "Error exporting subtitles", wxOK | wxICON_ERROR | wxCENTER, &d); wxMessageBox(to_wx(err.GetMessage()), "Error exporting subtitles", wxOK | wxICON_ERROR | wxCENTER, &d);
} }

View file

@ -69,7 +69,7 @@ FFmpegSourceProvider::FFmpegSourceProvider(agi::BackgroundRunner *br)
if (SUCCEEDED(res)) if (SUCCEEDED(res))
COMInited = true; COMInited = true;
else if (res != RPC_E_CHANGED_MODE) else if (res != RPC_E_CHANGED_MODE)
throw "COM initialization failure"; throw agi::EnvironmentError("COM initialization failure");
#endif #endif
// initialize ffmpegsource // initialize ffmpegsource
@ -87,7 +87,6 @@ FFMS_Index *FFmpegSourceProvider::DoIndexing(FFMS_Indexer *Indexer, agi::fs::pat
ErrInfo.BufferSize = sizeof(FFMSErrMsg); ErrInfo.BufferSize = sizeof(FFMSErrMsg);
ErrInfo.ErrorType = FFMS_ERROR_SUCCESS; ErrInfo.ErrorType = FFMS_ERROR_SUCCESS;
ErrInfo.SubType = FFMS_ERROR_SUCCESS; ErrInfo.SubType = FFMS_ERROR_SUCCESS;
std::string MsgString;
// index all audio tracks // index all audio tracks
FFMS_Index *Index; FFMS_Index *Index;
@ -103,11 +102,8 @@ FFMS_Index *FFmpegSourceProvider::DoIndexing(FFMS_Indexer *Indexer, agi::fs::pat
nullptr, nullptr, IndexEH, callback, ps, &ErrInfo); nullptr, nullptr, IndexEH, callback, ps, &ErrInfo);
}); });
if (Index == nullptr) { if (Index == nullptr)
MsgString += "Failed to index: "; throw agi::EnvironmentError(std::string("Failed to index: ") + ErrInfo.Buffer);
MsgString += ErrInfo.Buffer;
throw MsgString;
}
// write index to disk for later use // write index to disk for later use
FFMS_WriteIndex(CacheName.string().c_str(), Index, &ErrInfo); FFMS_WriteIndex(CacheName.string().c_str(), Index, &ErrInfo);
@ -214,7 +210,6 @@ agi::fs::path FFmpegSourceProvider::GetCacheFilename(agi::fs::path const& filena
return result; return result;
} }
/// @brief Starts the cache cleaner thread
void FFmpegSourceProvider::CleanCache() { void FFmpegSourceProvider::CleanCache() {
::CleanCache(config::path->Decode("?local/ffms2cache/"), ::CleanCache(config::path->Decode("?local/ffms2cache/"),
"*.ffindex", "*.ffindex",

View file

@ -37,12 +37,13 @@
#include "fft.h" #include "fft.h"
#ifndef WITH_FFTW3 #ifndef WITH_FFTW3
#include <libaegisub/exception.h>
#include <cmath> #include <cmath>
void FFT::DoTransform (size_t n_samples,float *input,float *output_r,float *output_i,bool inverse) { void FFT::DoTransform (size_t n_samples,float *input,float *output_r,float *output_i,bool inverse) {
if (!IsPowerOfTwo(n_samples)) { if (!IsPowerOfTwo(n_samples))
throw "FFT requires power of two input."; agi::InternalError(throw "FFT requires power of two input.");
}
// Inverse transform // Inverse transform
float angle_num = 2.0f * 3.1415926535897932384626433832795f; float angle_num = 2.0f * 3.1415926535897932384626433832795f;

View file

@ -38,6 +38,7 @@
#include "utils.h" #include "utils.h"
#include <libaegisub/color.h> #include <libaegisub/color.h>
#include <libaegisub/exception.h>
#include <wx/bitmap.h> #include <wx/bitmap.h>
#include <wx/dcmemory.h> #include <wx/dcmemory.h>
@ -151,7 +152,7 @@ class OpenGLTextTexture final : boost::noncopyable {
// Upload image to video memory // Upload image to video memory
glBindTexture(GL_TEXTURE_2D, tex); glBindTexture(GL_TEXTURE_2D, tex);
glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, imgw, imgh, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, &alpha[0]); glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, imgw, imgh, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, &alpha[0]);
if (glGetError()) throw "Internal OpenGL text renderer error: Error uploading glyph data to video memory."; if (glGetError()) throw agi::EnvironmentError("Internal OpenGL text renderer error: Error uploading glyph data to video memory.");
} }
public: public:
@ -173,7 +174,7 @@ public:
// Allocate texture // Allocate texture
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, nullptr); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, nullptr);
if (glGetError()) throw "Internal OpenGL text renderer error: Could not allocate Text Texture"; if (glGetError()) throw agi::EnvironmentError("Internal OpenGL text renderer error: Could not allocate text texture");
TryToInsert(glyph); TryToInsert(glyph);
} }

View file

@ -322,14 +322,6 @@ bool AegisubApp::OnInit() {
if (!files.empty()) if (!files.empty())
frame->context->project->LoadList(files); frame->context->project->LoadList(files);
} }
catch (const char *err) {
wxMessageBox(err, "Fatal error while initializing");
return false;
}
catch (wxString const& err) {
wxMessageBox(err, "Fatal error while initializing");
return false;
}
catch (agi::Exception const& e) { catch (agi::Exception const& e) {
wxMessageBox(to_wx(e.GetMessage()), "Fatal error while initializing"); wxMessageBox(to_wx(e.GetMessage()), "Fatal error while initializing");
return false; return false;
@ -432,12 +424,6 @@ bool AegisubApp::OnExceptionInMainLoop() {
catch (const std::exception &e) { catch (const std::exception &e) {
SHOW_EXCEPTION(to_wx(e.what())); SHOW_EXCEPTION(to_wx(e.what()));
} }
catch (const char *e) {
SHOW_EXCEPTION(to_wx(e));
}
catch (const wxString &e) {
SHOW_EXCEPTION(e);
}
catch (...) { catch (...) {
SHOW_EXCEPTION("Unknown error"); SHOW_EXCEPTION("Unknown error");
} }
@ -453,8 +439,6 @@ int AegisubApp::OnRun() {
if (m_exitOnFrameDelete == Later) m_exitOnFrameDelete = Yes; if (m_exitOnFrameDelete == Later) m_exitOnFrameDelete = Yes;
return MainLoop(); return MainLoop();
} }
catch (const wxString &err) { error = from_wx(err); }
catch (const char *err) { error = err; }
catch (const std::exception &e) { error = std::string("std::exception: ") + e.what(); } catch (const std::exception &e) { error = std::string("std::exception: ") + e.what(); }
catch (const agi::Exception &e) { error = "agi::exception: " + e.GetMessage(); } catch (const agi::Exception &e) { error = "agi::exception: " + e.GetMessage(); }
catch (...) { error = "Program terminated in error."; } catch (...) { error = "Program terminated in error."; }

View file

@ -214,7 +214,7 @@ ProjectProperties SubsController::Load(agi::fs::path const& filename, std::strin
void SubsController::Save(agi::fs::path const& filename, std::string const& encoding) { void SubsController::Save(agi::fs::path const& filename, std::string const& encoding) {
const SubtitleFormat *writer = SubtitleFormat::GetWriter(filename); const SubtitleFormat *writer = SubtitleFormat::GetWriter(filename);
if (!writer) if (!writer)
throw "Unknown file type."; throw agi::InvalidInputException("Unknown file type.");
int old_autosaved_commit_id = autosaved_commit_id, old_saved_commit_id = saved_commit_id; int old_autosaved_commit_id = autosaved_commit_id, old_saved_commit_id = saved_commit_id;
try { try {

View file

@ -34,19 +34,12 @@
DEFINE_EXCEPTION(AssParseError, SubtitleFormatParseError); DEFINE_EXCEPTION(AssParseError, SubtitleFormatParseError);
void AssSubtitleFormat::ReadFile(AssFile *target, agi::fs::path const& filename, agi::vfr::Framerate const& fps, std::string const& encoding) const { void AssSubtitleFormat::ReadFile(AssFile *target, agi::fs::path const& filename, agi::vfr::Framerate const& fps, std::string const& encoding) const {
TextFileReader file(filename, encoding);
int version = !agi::fs::HasExtension(filename, "ssa"); int version = !agi::fs::HasExtension(filename, "ssa");
AssParser parser(target, version);
while (file.HasMoreLines()) { TextFileReader file(filename, encoding);
std::string line = file.ReadLineFromFile(); AssParser parser(target, version);
try { while (file.HasMoreLines())
parser.AddLine(line); parser.AddLine(file.ReadLineFromFile());
}
catch (const char *err) {
throw AssParseError("Error processing line: " + line + ": " + err);
}
}
} }
#ifdef _WIN32 #ifdef _WIN32

View file

@ -60,8 +60,7 @@ std::unique_ptr<SubtitlesProvider> SubtitlesProviderFactory::GetProvider(agi::Ba
if (provider) return provider; if (provider) return provider;
} }
catch (agi::UserCancelException const&) { throw; } catch (agi::UserCancelException const&) { throw; }
catch (std::string const& err) { error += factory->name + ": " + err + "\n"; } catch (agi::Exception const& err) { error += factory->name + ": " + err.GetMessage() + "\n"; }
catch (const char *err) { error += factory->name + ": " + std::string(err) + "\n"; }
catch (...) { error += factory->name + ": Unknown error\n"; } catch (...) { error += factory->name + ": Unknown error\n"; }
} }

View file

@ -131,7 +131,7 @@ public:
void LoadSubtitles(const char *data, size_t len) override { void LoadSubtitles(const char *data, size_t len) override {
if (ass_track) ass_free_track(ass_track); if (ass_track) ass_free_track(ass_track);
ass_track = ass_read_memory(library, const_cast<char *>(data), len, nullptr); ass_track = ass_read_memory(library, const_cast<char *>(data), len, nullptr);
if (!ass_track) throw "libass failed to load subtitles."; if (!ass_track) throw agi::InternalError("libass failed to load subtitles.");
} }
void DrawSubtitles(VideoFrame &dst, double time) override; void DrawSubtitles(VideoFrame &dst, double time) override;

View file

@ -132,11 +132,8 @@ FFmpegSourceVideoProvider::FFmpegSourceVideoProvider(agi::fs::path const& filena
LoadVideo(filename, colormatrix); LoadVideo(filename, colormatrix);
} }
catch (std::string const& err) { catch (agi::EnvironmentError const& err) {
throw VideoOpenError(err); throw VideoOpenError(err.GetMessage());
}
catch (const char * err) {
throw VideoOpenError(err);
} }
void FFmpegSourceVideoProvider::LoadVideo(agi::fs::path const& filename, std::string const& colormatrix) { void FFmpegSourceVideoProvider::LoadVideo(agi::fs::path const& filename, std::string const& colormatrix) {

View file

@ -402,7 +402,7 @@ std::shared_ptr<VideoFrame> YUV4MPEGVideoProvider::GetFrame(int n) {
break; break;
/// @todo add support for more pixel formats /// @todo add support for more pixel formats
default: default:
throw "YUV4MPEG video provider: GetFrame: Unsupported source colorspace"; throw VideoNotSupported("YUV4MPEG video provider: GetFrame: Unsupported source colorspace");
} }
auto src_y = reinterpret_cast<const unsigned char *>(file.read(seek_table[n], luma_sz + chroma_sz * 2)); auto src_y = reinterpret_cast<const unsigned char *>(file.read(seek_table[n], luma_sz + chroma_sz * 2));