Eliminate some gratuitous exceptions

This commit is contained in:
Thomas Goyne 2014-12-12 08:19:10 -08:00
parent 0416188235
commit 879788fe83
4 changed files with 7 additions and 20 deletions

View file

@ -98,12 +98,9 @@ public:
break;
default:
throw UnknownCharset("Unknown character set.");
return;
}
if (list.empty() && (mInputState == eHighbyte))
throw UnknownCharset("Unknown character set.");
typedef std::pair<float, std::string> const& result;
sort(begin(list), end(list), [](result lft, result rgt) { return lft.first > rgt.first; });
}

View file

@ -26,9 +26,6 @@ namespace agi {
/// Character set conversion and detection.
namespace charset {
DEFINE_EXCEPTION(CharsetError, agi::Exception);
DEFINE_EXCEPTION(UnknownCharset, CharsetError);
/// List of detected encodings.
typedef std::vector<std::pair<float, std::string>> CharsetListDetected;

View file

@ -124,14 +124,14 @@ struct COMInitialization {
}
/// @brief Initialise the COM library as single-threaded apartment if isn't already inited by us
void Init()
bool Init()
{
if (!inited)
{
if (FAILED(CoInitialize(nullptr)))
throw std::exception();
inited = true;
if (SUCCEEDED(CoInitialize(nullptr)))
inited = true;
}
return inited;
}
};
@ -302,8 +302,7 @@ unsigned int __stdcall DirectSoundPlayer2Thread::ThreadProc(void *parameter)
void DirectSoundPlayer2Thread::Run()
{
COMInitialization COM_library;
try { COM_library.Init(); }
catch (std::exception e)
if (!COM_library.Init())
REPORT_ERROR("Could not initialise COM")
// Create DirectSound object

View file

@ -49,13 +49,7 @@
namespace CharSetDetect {
std::string GetEncoding(agi::fs::path const& filename) {
agi::charset::CharsetListDetected list;
try {
list = agi::charset::DetectAll(filename);
} catch (const agi::charset::UnknownCharset&) {
// will be set to the full list of charsets below
}
auto list = agi::charset::DetectAll(filename);
if (list.size() == 1) {
auto charset = list.begin();