diff --git a/src/ass_exporter.cpp b/src/ass_exporter.cpp index 1935284cb..777f967eb 100644 --- a/src/ass_exporter.cpp +++ b/src/ass_exporter.cpp @@ -67,8 +67,7 @@ void AssExporter::DrawSettings(wxWindow *parent, wxSizer *target_sizer) { void AssExporter::AddFilter(std::string const& name) { auto filter = AssExportFilterChain::GetFilter(name); - - if (!filter) throw "Filter not found: " + name; + if (!filter) throw agi::InternalError("Filter not found: " + name); 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); if (!writer) - throw "Unknown file type."; + throw agi::InvalidInputException("Unknown file type."); 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); if (filter) return filter->GetDescription(); - throw "Filter not found: " + name; + throw agi::InternalError("Filter not found: " + name); } diff --git a/src/async_video_provider.cpp b/src/async_video_provider.cpp index ba9cbe287..d1b6fbce9 100644 --- a/src/async_video_provider.cpp +++ b/src/async_video_provider.cpp @@ -58,7 +58,7 @@ std::shared_ptr AsyncVideoProvider::ProcFrame(int frame_number, doub } } } - catch (std::string const& err) { throw SubtitlesProviderErrorEvent(err); } + catch (agi::Exception const& err) { throw SubtitlesProviderErrorEvent(err.GetMessage()); } try { subs_provider->DrawSubtitles(*frame, time / 1000.); @@ -72,8 +72,8 @@ static std::unique_ptr get_subs_provider(wxEvtHandler *evt_ha try { return SubtitlesProviderFactory::GetProvider(br); } - catch (std::string const& err) { - evt_handler->AddPendingEvent(SubtitlesProviderErrorEvent(err)); + catch (agi::Exception const& err) { + evt_handler->AddPendingEvent(SubtitlesProviderErrorEvent(err.GetMessage())); return nullptr; } } diff --git a/src/audio_provider_ffmpegsource.cpp b/src/audio_provider_ffmpegsource.cpp index 9e9e9183f..3a89f6506 100644 --- a/src/audio_provider_ffmpegsource.cpp +++ b/src/audio_provider_ffmpegsource.cpp @@ -78,11 +78,8 @@ FFmpegSourceAudioProvider::FFmpegSourceAudioProvider(agi::fs::path const& filena LoadAudio(filename); } -catch (std::string const& err) { - throw agi::AudioProviderOpenError(err); -} -catch (const char *err) { - throw agi::AudioProviderOpenError(err); +catch (agi::EnvironmentError const& err) { + throw agi::AudioProviderOpenError(err.GetMessage()); } void FFmpegSourceAudioProvider::LoadAudio(agi::fs::path const& filename) { diff --git a/src/command/subtitle.cpp b/src/command/subtitle.cpp index 24175191c..02bc640cf 100644 --- a/src/command/subtitle.cpp +++ b/src/command/subtitle.cpp @@ -322,9 +322,6 @@ static void save_subtitles(agi::Context *c, agi::fs::path filename) { catch (const agi::Exception& err) { 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 (...) { wxMessageBox("Unknown error", "Error", wxOK | wxICON_ERROR | wxCENTER, c->parent); } diff --git a/src/dialog_export.cpp b/src/dialog_export.cpp index f038bf1b7..79f649170 100644 --- a/src/dialog_export.cpp +++ b/src/dialog_export.cpp @@ -199,14 +199,7 @@ void DialogExport::OnProcess(wxCommandEvent &) { c->ass->Properties.export_encoding = from_wx(charset_list->GetStringSelection()); exporter.Export(filename, from_wx(charset_list->GetStringSelection()), &d); } - 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::UserCancelException const&) { } catch (agi::Exception const& err) { wxMessageBox(to_wx(err.GetMessage()), "Error exporting subtitles", wxOK | wxICON_ERROR | wxCENTER, &d); } diff --git a/src/ffmpegsource_common.cpp b/src/ffmpegsource_common.cpp index 1ff0776e9..705c93bd0 100644 --- a/src/ffmpegsource_common.cpp +++ b/src/ffmpegsource_common.cpp @@ -69,7 +69,7 @@ FFmpegSourceProvider::FFmpegSourceProvider(agi::BackgroundRunner *br) if (SUCCEEDED(res)) COMInited = true; else if (res != RPC_E_CHANGED_MODE) - throw "COM initialization failure"; + throw agi::EnvironmentError("COM initialization failure"); #endif // initialize ffmpegsource @@ -87,7 +87,6 @@ FFMS_Index *FFmpegSourceProvider::DoIndexing(FFMS_Indexer *Indexer, agi::fs::pat ErrInfo.BufferSize = sizeof(FFMSErrMsg); ErrInfo.ErrorType = FFMS_ERROR_SUCCESS; ErrInfo.SubType = FFMS_ERROR_SUCCESS; - std::string MsgString; // index all audio tracks FFMS_Index *Index; @@ -103,11 +102,8 @@ FFMS_Index *FFmpegSourceProvider::DoIndexing(FFMS_Indexer *Indexer, agi::fs::pat nullptr, nullptr, IndexEH, callback, ps, &ErrInfo); }); - if (Index == nullptr) { - MsgString += "Failed to index: "; - MsgString += ErrInfo.Buffer; - throw MsgString; - } + if (Index == nullptr) + throw agi::EnvironmentError(std::string("Failed to index: ") + ErrInfo.Buffer); // write index to disk for later use FFMS_WriteIndex(CacheName.string().c_str(), Index, &ErrInfo); @@ -214,7 +210,6 @@ agi::fs::path FFmpegSourceProvider::GetCacheFilename(agi::fs::path const& filena return result; } -/// @brief Starts the cache cleaner thread void FFmpegSourceProvider::CleanCache() { ::CleanCache(config::path->Decode("?local/ffms2cache/"), "*.ffindex", diff --git a/src/fft.cpp b/src/fft.cpp index 3de4e3a54..82a9af862 100644 --- a/src/fft.cpp +++ b/src/fft.cpp @@ -37,12 +37,13 @@ #include "fft.h" #ifndef WITH_FFTW3 +#include + #include void FFT::DoTransform (size_t n_samples,float *input,float *output_r,float *output_i,bool inverse) { - if (!IsPowerOfTwo(n_samples)) { - throw "FFT requires power of two input."; - } + if (!IsPowerOfTwo(n_samples)) + agi::InternalError(throw "FFT requires power of two input."); // Inverse transform float angle_num = 2.0f * 3.1415926535897932384626433832795f; diff --git a/src/gl_text.cpp b/src/gl_text.cpp index 50f83971d..94f866961 100644 --- a/src/gl_text.cpp +++ b/src/gl_text.cpp @@ -38,6 +38,7 @@ #include "utils.h" #include +#include #include #include @@ -151,7 +152,7 @@ class OpenGLTextTexture final : boost::noncopyable { // Upload image to video memory glBindTexture(GL_TEXTURE_2D, tex); 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: @@ -173,7 +174,7 @@ public: // Allocate texture 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); } diff --git a/src/main.cpp b/src/main.cpp index 2473af282..5ed15e0c0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -322,14 +322,6 @@ bool AegisubApp::OnInit() { if (!files.empty()) 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) { wxMessageBox(to_wx(e.GetMessage()), "Fatal error while initializing"); return false; @@ -432,12 +424,6 @@ bool AegisubApp::OnExceptionInMainLoop() { catch (const std::exception &e) { SHOW_EXCEPTION(to_wx(e.what())); } - catch (const char *e) { - SHOW_EXCEPTION(to_wx(e)); - } - catch (const wxString &e) { - SHOW_EXCEPTION(e); - } catch (...) { SHOW_EXCEPTION("Unknown error"); } @@ -453,8 +439,6 @@ int AegisubApp::OnRun() { if (m_exitOnFrameDelete == Later) m_exitOnFrameDelete = Yes; 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 agi::Exception &e) { error = "agi::exception: " + e.GetMessage(); } catch (...) { error = "Program terminated in error."; } diff --git a/src/subs_controller.cpp b/src/subs_controller.cpp index ff43a25c9..5aff32e18 100644 --- a/src/subs_controller.cpp +++ b/src/subs_controller.cpp @@ -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) { const SubtitleFormat *writer = SubtitleFormat::GetWriter(filename); 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; try { diff --git a/src/subtitle_format_ass.cpp b/src/subtitle_format_ass.cpp index 107884a7b..77184df4e 100644 --- a/src/subtitle_format_ass.cpp +++ b/src/subtitle_format_ass.cpp @@ -34,19 +34,12 @@ DEFINE_EXCEPTION(AssParseError, SubtitleFormatParseError); 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"); - AssParser parser(target, version); - while (file.HasMoreLines()) { - std::string line = file.ReadLineFromFile(); - try { - parser.AddLine(line); - } - catch (const char *err) { - throw AssParseError("Error processing line: " + line + ": " + err); - } - } + TextFileReader file(filename, encoding); + AssParser parser(target, version); + while (file.HasMoreLines()) + parser.AddLine(file.ReadLineFromFile()); } #ifdef _WIN32 diff --git a/src/subtitles_provider.cpp b/src/subtitles_provider.cpp index 2c19f73a5..9fc56f8c4 100644 --- a/src/subtitles_provider.cpp +++ b/src/subtitles_provider.cpp @@ -60,8 +60,7 @@ std::unique_ptr SubtitlesProviderFactory::GetProvider(agi::Ba if (provider) return provider; } catch (agi::UserCancelException const&) { throw; } - catch (std::string const& err) { error += factory->name + ": " + err + "\n"; } - catch (const char *err) { error += factory->name + ": " + std::string(err) + "\n"; } + catch (agi::Exception const& err) { error += factory->name + ": " + err.GetMessage() + "\n"; } catch (...) { error += factory->name + ": Unknown error\n"; } } diff --git a/src/subtitles_provider_libass.cpp b/src/subtitles_provider_libass.cpp index 183fa236f..0d2bfdd01 100644 --- a/src/subtitles_provider_libass.cpp +++ b/src/subtitles_provider_libass.cpp @@ -131,7 +131,7 @@ public: void LoadSubtitles(const char *data, size_t len) override { if (ass_track) ass_free_track(ass_track); ass_track = ass_read_memory(library, const_cast(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; diff --git a/src/video_provider_ffmpegsource.cpp b/src/video_provider_ffmpegsource.cpp index a3f307bbc..9c8b4cdc5 100644 --- a/src/video_provider_ffmpegsource.cpp +++ b/src/video_provider_ffmpegsource.cpp @@ -132,11 +132,8 @@ FFmpegSourceVideoProvider::FFmpegSourceVideoProvider(agi::fs::path const& filena LoadVideo(filename, colormatrix); } -catch (std::string const& err) { - throw VideoOpenError(err); -} -catch (const char * err) { - throw VideoOpenError(err); +catch (agi::EnvironmentError const& err) { + throw VideoOpenError(err.GetMessage()); } void FFmpegSourceVideoProvider::LoadVideo(agi::fs::path const& filename, std::string const& colormatrix) { diff --git a/src/video_provider_yuv4mpeg.cpp b/src/video_provider_yuv4mpeg.cpp index 5694aca9b..6165fe40e 100644 --- a/src/video_provider_yuv4mpeg.cpp +++ b/src/video_provider_yuv4mpeg.cpp @@ -402,7 +402,7 @@ std::shared_ptr YUV4MPEGVideoProvider::GetFrame(int n) { break; /// @todo add support for more pixel formats default: - throw "YUV4MPEG video provider: GetFrame: Unsupported source colorspace"; + throw VideoNotSupported("YUV4MPEG video provider: GetFrame: Unsupported source colorspace"); } auto src_y = reinterpret_cast(file.read(seek_table[n], luma_sz + chroma_sz * 2));