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) {
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);
}

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 {
subs_provider->DrawSubtitles(*frame, time / 1000.);
@ -72,8 +72,8 @@ static std::unique_ptr<SubtitlesProvider> 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;
}
}

View File

@ -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) {

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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",

View File

@ -37,12 +37,13 @@
#include "fft.h"
#ifndef WITH_FFTW3
#include <libaegisub/exception.h>
#include <cmath>
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;

View File

@ -38,6 +38,7 @@
#include "utils.h"
#include <libaegisub/color.h>
#include <libaegisub/exception.h>
#include <wx/bitmap.h>
#include <wx/dcmemory.h>
@ -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);
}

View File

@ -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."; }

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) {
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 {

View File

@ -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

View File

@ -60,8 +60,7 @@ std::unique_ptr<SubtitlesProvider> 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"; }
}

View File

@ -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<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;

View File

@ -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) {

View File

@ -402,7 +402,7 @@ std::shared_ptr<VideoFrame> 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<const unsigned char *>(file.read(seek_table[n], luma_sz + chroma_sz * 2));