diff --git a/src/openrct2-ui/drawing/engines/opengl/OpenGLDrawingEngine.cpp b/src/openrct2-ui/drawing/engines/opengl/OpenGLDrawingEngine.cpp index 8de27007f7..ad97cf38dd 100644 --- a/src/openrct2-ui/drawing/engines/opengl/OpenGLDrawingEngine.cpp +++ b/src/openrct2-ui/drawing/engines/opengl/OpenGLDrawingEngine.cpp @@ -22,7 +22,6 @@ #include #include -#include #include #include #include @@ -182,13 +181,13 @@ public: { char szRequiredVersion[32]; snprintf(szRequiredVersion, 32, "OpenGL %d.%d", requiredVersion.Major, requiredVersion.Minor); - throw Exception(std::string(szRequiredVersion) + std::string(" not available.")); + throw std::runtime_error(std::string(szRequiredVersion) + std::string(" not available.")); } SDL_GL_MakeCurrent(_window, _context); if (!OpenGLAPI::Initialise()) { - throw Exception("Unable to initialise OpenGL."); + throw std::runtime_error("Unable to initialise OpenGL."); } _drawingContext->Initialise(); diff --git a/src/openrct2-ui/drawing/engines/opengl/OpenGLShaderProgram.cpp b/src/openrct2-ui/drawing/engines/opengl/OpenGLShaderProgram.cpp index cfaab921a7..4a8d18f3be 100644 --- a/src/openrct2-ui/drawing/engines/opengl/OpenGLShaderProgram.cpp +++ b/src/openrct2-ui/drawing/engines/opengl/OpenGLShaderProgram.cpp @@ -17,7 +17,6 @@ #ifndef DISABLE_OPENGL #include -#include #include #include #include @@ -51,7 +50,7 @@ OpenGLShader::OpenGLShader(const char * name, GLenum type) Console::Error::WriteLine("Error compiling %s", path); Console::Error::WriteLine(buffer); - throw Exception("Error compiling shader."); + throw std::runtime_error("Error compiling shader."); } } @@ -115,7 +114,7 @@ OpenGLShaderProgram::OpenGLShaderProgram(const char * name) Console::Error::WriteLine("Error linking %s", name); Console::Error::WriteLine(buffer); - throw Exception("Failed to link OpenGL shader."); + throw std::runtime_error("Failed to link OpenGL shader."); } } diff --git a/src/openrct2-ui/input/KeyboardShortcuts.cpp b/src/openrct2-ui/input/KeyboardShortcuts.cpp index 642856b713..3d52632612 100644 --- a/src/openrct2-ui/input/KeyboardShortcuts.cpp +++ b/src/openrct2-ui/input/KeyboardShortcuts.cpp @@ -70,9 +70,9 @@ bool KeyboardShortcuts::Load() } } } - catch (const Exception &ex) + catch (const std::exception &ex) { - Console::WriteLine("Error reading shortcut keys: %s", ex.GetMessage()); + Console::WriteLine("Error reading shortcut keys: %s", ex.what()); } return result; } @@ -91,9 +91,9 @@ bool KeyboardShortcuts::Save() } result = true; } - catch (const Exception &ex) + catch (const std::exception &ex) { - Console::WriteLine("Error writing shortcut keys: %s", ex.GetMessage()); + Console::WriteLine("Error writing shortcut keys: %s", ex.what()); } return result; } diff --git a/src/openrct2/Context.cpp b/src/openrct2/Context.cpp index 26cd6d9e8e..811676692e 100644 --- a/src/openrct2/Context.cpp +++ b/src/openrct2/Context.cpp @@ -448,9 +448,9 @@ namespace OpenRCT2 handle_park_load_failure_with_title_opt(&result, path.c_str(), loadTitleScreenFirstOnFail); } } - catch (const Exception& e) + catch (const std::exception &e) { - Console::Error::WriteLine(e.GetMessage()); + Console::Error::WriteLine(e.what()); } } else diff --git a/src/openrct2/FileClassifier.cpp b/src/openrct2/FileClassifier.cpp index a536a9cd94..7231889b58 100644 --- a/src/openrct2/FileClassifier.cpp +++ b/src/openrct2/FileClassifier.cpp @@ -34,7 +34,7 @@ bool TryClassifyFile(const std::string &path, ClassifiedFileInfo * result) auto fs = FileStream(path, FILE_MODE_OPEN); return TryClassifyFile(&fs, result); } - catch (Exception) + catch (const std::exception &) { return false; } @@ -87,10 +87,10 @@ static bool TryClassifyAsS6(IStream * stream, ClassifiedFileInfo * result) result->Version = s6Header.version; success = true; } - catch (const Exception& e) + catch (const std::exception &e) { // Exceptions are likely to occur if file is not S6 format - log_verbose(e.GetMessage()); + log_verbose(e.what()); } stream->SetPosition(originalPosition); return success; @@ -123,9 +123,9 @@ static bool TryClassifyAsS4(IStream * stream, ClassifiedFileInfo * result) success = true; } } - catch (const Exception& e) + catch (const std::exception &e) { - Console::Error::WriteLine(e.GetMessage()); + Console::Error::WriteLine(e.what()); } stream->SetPosition(originalPosition); @@ -158,9 +158,9 @@ static bool TryClassifyAsTD4_TD6(IStream * stream, ClassifiedFileInfo * result) } } } - catch (const Exception& e) + catch (const std::exception& e) { - Console::Error::WriteLine(e.GetMessage()); + Console::Error::WriteLine(e.what()); } return success; diff --git a/src/openrct2/Imaging.cpp b/src/openrct2/Imaging.cpp index d5ad89f49b..6d3ec2e1c6 100644 --- a/src/openrct2/Imaging.cpp +++ b/src/openrct2/Imaging.cpp @@ -17,7 +17,6 @@ #pragma warning(disable : 4611) // interaction between '_setjmp' and C++ object destruction is non-portable #include -#include "core/Exception.hpp" #include "core/FileStream.hpp" #include "core/Guard.hpp" #include "core/Memory.hpp" @@ -133,7 +132,7 @@ namespace Imaging return true; } - catch (Exception) + catch (const std::exception &) { *pixels = nullptr; if (width != nullptr) *width = 0; @@ -183,7 +182,7 @@ namespace Imaging // Set error handler if (setjmp(png_jmpbuf(png_ptr))) { - throw Exception("PNG ERROR"); + throw std::runtime_error("PNG ERROR"); } // Write header @@ -207,7 +206,7 @@ namespace Imaging png_write_end(png_ptr, nullptr); result = true; } - catch (Exception) + catch (const std::exception &) { } @@ -243,7 +242,7 @@ namespace Imaging // Set error handler if (setjmp(png_jmpbuf(png_ptr))) { - throw Exception("PNG ERROR"); + throw std::runtime_error("PNG ERROR"); } // Write header @@ -265,7 +264,7 @@ namespace Imaging png_write_end(png_ptr, nullptr); result = true; } - catch (Exception) + catch (const std::exception &) { } diff --git a/src/openrct2/PlatformEnvironment.cpp b/src/openrct2/PlatformEnvironment.cpp index 9a1e80783a..850f9d3777 100644 --- a/src/openrct2/PlatformEnvironment.cpp +++ b/src/openrct2/PlatformEnvironment.cpp @@ -16,7 +16,6 @@ #include "config/Config.h" #include "core/Console.hpp" -#include "core/Exception.hpp" #include "core/Guard.hpp" #include "core/Path.hpp" #include "core/String.hpp" diff --git a/src/openrct2/audio/Audio.cpp b/src/openrct2/audio/Audio.cpp index 68a6e2d1f4..cada0c7df3 100644 --- a/src/openrct2/audio/Audio.cpp +++ b/src/openrct2/audio/Audio.cpp @@ -364,7 +364,7 @@ void audio_init_ride_sounds_and_info() rideMusicInfo->length = fs.GetLength(); } } - catch (const Exception &) + catch (const std::exception &) { } } diff --git a/src/openrct2/cmdline/ConvertCommand.cpp b/src/openrct2/cmdline/ConvertCommand.cpp index 9ce7206972..a246af1794 100644 --- a/src/openrct2/cmdline/ConvertCommand.cpp +++ b/src/openrct2/cmdline/ConvertCommand.cpp @@ -17,7 +17,6 @@ #include #include "../common.h" #include "../core/Console.hpp" -#include "../core/Exception.hpp" #include "../core/Guard.hpp" #include "../core/Path.hpp" #include "../FileClassifier.h" @@ -112,9 +111,9 @@ exitcode_t CommandLine::HandleCommandConvert(CommandLineArgEnumerator * enumerat importer->Load(sourcePath); importer->Import(); } - catch (const Exception &ex) + catch (const std::exception &ex) { - Console::Error::WriteLine(ex.GetMessage()); + Console::Error::WriteLine(ex.what()); return EXITCODE_FAIL; } @@ -143,9 +142,9 @@ exitcode_t CommandLine::HandleCommandConvert(CommandLineArgEnumerator * enumerat exporter->SaveGame(destinationPath); } } - catch (const Exception &ex) + catch (const std::exception &ex) { - Console::Error::WriteLine(ex.GetMessage()); + Console::Error::WriteLine(ex.what()); return EXITCODE_FAIL; } diff --git a/src/openrct2/config/Config.cpp b/src/openrct2/config/Config.cpp index 911809759b..71f6dfb2b9 100644 --- a/src/openrct2/config/Config.cpp +++ b/src/openrct2/config/Config.cpp @@ -17,7 +17,6 @@ #include #include "../Context.h" #include "../core/Console.hpp" -#include "../core/Exception.hpp" #include "../core/File.h" #include "../core/FileStream.hpp" #include "../core/Memory.hpp" @@ -538,7 +537,7 @@ namespace Config ReadFont(reader.get()); return true; } - catch (const Exception &) + catch (const std::exception &) { return false; } @@ -559,7 +558,7 @@ namespace Config ReadFont(reader.get()); return true; } - catch (const Exception &) + catch (const std::exception &) { return false; } @@ -580,10 +579,10 @@ namespace Config WriteFont(writer.get()); return true; } - catch (const Exception &ex) + catch (const std::exception &ex) { Console::WriteLine("Error saving to '%s'", path.c_str()); - Console::WriteLine(ex.GetMessage()); + Console::WriteLine(ex.what()); return false; } } diff --git a/src/openrct2/core/Diagnostics.cpp b/src/openrct2/core/Diagnostics.cpp index 9ef48d0921..c88d974bc3 100644 --- a/src/openrct2/core/Diagnostics.cpp +++ b/src/openrct2/core/Diagnostics.cpp @@ -17,7 +17,6 @@ #if defined(DEBUG) && defined(_WIN32) #define WIN32_LEAN_AND_MEAN #include - #undef GetMessage #endif #include "Diagnostics.hpp" diff --git a/src/openrct2/core/Exception.hpp b/src/openrct2/core/Exception.hpp deleted file mode 100644 index 382c58c4b0..0000000000 --- a/src/openrct2/core/Exception.hpp +++ /dev/null @@ -1,38 +0,0 @@ -#pragma region Copyright (c) 2014-2017 OpenRCT2 Developers -/***************************************************************************** - * OpenRCT2, an open source clone of Roller Coaster Tycoon 2. - * - * OpenRCT2 is the work of many authors, a full list can be found in contributors.md - * For more information, visit https://github.com/OpenRCT2/OpenRCT2 - * - * OpenRCT2 is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * A full copy of the GNU General Public License can be found in licence.txt - *****************************************************************************/ -#pragma endregion - -#pragma once - -#include "../common.h" - -#include -#include - -class Exception : public std::exception -{ -public: - Exception() : Exception("") { } - explicit Exception(const char * message) : Exception(std::string(message)) { } - explicit Exception(const std::string &message) : std::exception(), _message(message) { } - - virtual ~Exception() { } - - const char * what() const throw() override { return _message.c_str(); } - const char * GetMessage() const { return _message.c_str(); } - -private: - std::string _message; -}; diff --git a/src/openrct2/core/File.cpp b/src/openrct2/core/File.cpp index 03bde506ca..aea292af82 100644 --- a/src/openrct2/core/File.cpp +++ b/src/openrct2/core/File.cpp @@ -143,7 +143,7 @@ extern "C" *outBuffer = File::ReadAllBytes(String::ToStd(path), outLength); return true; } - catch (const Exception &) + catch (const std::exception &) { return false; } @@ -156,7 +156,7 @@ extern "C" File::WriteAllBytes(String::ToStd(path), buffer, length); return true; } - catch (const Exception &) + catch (const std::exception &) { return false; } diff --git a/src/openrct2/core/Guard.cpp b/src/openrct2/core/Guard.cpp index 265b27ec99..833e51f7ec 100644 --- a/src/openrct2/core/Guard.cpp +++ b/src/openrct2/core/Guard.cpp @@ -23,7 +23,6 @@ #ifdef _WIN32 #define WIN32_LEAN_AND_MEAN #include -#undef GetMessage #endif #include "../Version.h" diff --git a/src/openrct2/core/IStream.hpp b/src/openrct2/core/IStream.hpp index 1be8d4b3ff..ab99d822be 100644 --- a/src/openrct2/core/IStream.hpp +++ b/src/openrct2/core/IStream.hpp @@ -16,9 +16,9 @@ #pragma once +#include #include #include "../common.h" -#include "Exception.hpp" #include "Memory.hpp" enum { @@ -112,9 +112,8 @@ interface IStream void WriteString(const std::string &string); }; -class IOException : public Exception +class IOException : public std::runtime_error { public: - explicit IOException(const char * message) : Exception(message) { } - explicit IOException(const std::string &message) : Exception(message) { } + explicit IOException(const std::string &message) : std::runtime_error(message) { } }; diff --git a/src/openrct2/core/Json.hpp b/src/openrct2/core/Json.hpp index 726b2f00e4..f31f22a2ea 100644 --- a/src/openrct2/core/Json.hpp +++ b/src/openrct2/core/Json.hpp @@ -16,10 +16,10 @@ #pragma once +#include #include #include "../common.h" -#include "Exception.hpp" namespace Json { @@ -30,13 +30,13 @@ namespace Json void WriteToFile(const utf8 * path, const json_t * json, size_t flags = 0); } -class JsonException final : public Exception +class JsonException final : public std::runtime_error { private: json_error_t _jsonError = { 0 }; public: - explicit JsonException(const char * message) : Exception(message) { } + explicit JsonException(const std::string &message) : std::runtime_error(message) { } explicit JsonException(const json_error_t * jsonError) : JsonException(jsonError->text) { diff --git a/src/openrct2/core/Zip.cpp b/src/openrct2/core/Zip.cpp index de7b34c757..b58e27f6b5 100644 --- a/src/openrct2/core/Zip.cpp +++ b/src/openrct2/core/Zip.cpp @@ -153,7 +153,7 @@ namespace Zip { result = new ZipArchive(path, access); } - catch (Exception) + catch (const std::exception &) { } return result; diff --git a/src/openrct2/core/ZipAndroid.cpp b/src/openrct2/core/ZipAndroid.cpp index 726bb82281..59bd4c43b1 100644 --- a/src/openrct2/core/ZipAndroid.cpp +++ b/src/openrct2/core/ZipAndroid.cpp @@ -148,7 +148,7 @@ namespace Zip { try { result = new ZipArchive(path, access); } - catch (Exception) { + catch (const std::exception &) { } return result; } diff --git a/src/openrct2/drawing/NewDrawing.cpp b/src/openrct2/drawing/NewDrawing.cpp index 336d94f450..347704b860 100644 --- a/src/openrct2/drawing/NewDrawing.cpp +++ b/src/openrct2/drawing/NewDrawing.cpp @@ -17,7 +17,6 @@ #include #include "../Context.h" #include "../ui/UiContext.h" -#include "../core/Exception.hpp" #include "../interface/Screenshot.h" #include "../paint/Painter.h" #include "IDrawingContext.h" @@ -108,7 +107,7 @@ extern "C" drawingEngine->SetVSync(gConfigGeneral.use_vsync); _drawingEngine = drawingEngine; } - catch (const Exception &ex) + catch (const std::exception &ex) { delete _painter; _painter = nullptr; @@ -117,13 +116,13 @@ extern "C" if (_drawingEngineType == DRAWING_ENGINE_SOFTWARE) { _drawingEngineType = DRAWING_ENGINE_NONE; - log_error(ex.GetMessage()); + log_error(ex.what()); log_fatal("Unable to initialise a drawing engine."); exit(-1); } else { - log_error(ex.GetMessage()); + log_error(ex.what()); log_error("Unable to initialise drawing engine. Falling back to software."); // Fallback to software diff --git a/src/openrct2/drawing/Sprite.cpp b/src/openrct2/drawing/Sprite.cpp index e00ed9927d..9770497b7d 100644 --- a/src/openrct2/drawing/Sprite.cpp +++ b/src/openrct2/drawing/Sprite.cpp @@ -15,7 +15,7 @@ #pragma endregion #include - +#include #include "../common.h" #include "../config/Config.h" #include "../Context.h" @@ -69,7 +69,7 @@ static inline uint32 rctc_to_rct2_index(uint32 image) else if (image >= 23804 && image < 24670) return image - 43; else if (image >= 24674 && image < 28244) return image - 47; else if (image >= 28246 ) return image - 49; - else throw Exception("Invalid RCTC g1.dat file"); + else throw std::runtime_error("Invalid RCTC g1.dat file"); } static void read_and_convert_gxdat(IStream * stream, size_t count, bool is_rctc, rct_g1_element *elements) @@ -206,7 +206,7 @@ extern "C" if (header.num_entries < SPR_G1_END) { - throw Exception("Not enough elements in g1.dat"); + throw std::runtime_error("Not enough elements in g1.dat"); } // Read element headers @@ -226,7 +226,7 @@ extern "C" } return true; } - catch (const Exception &) + catch (const std::exception &) { log_fatal("Unable to load g1 graphics"); if (!gOpenRCT2Headless) @@ -283,7 +283,7 @@ extern "C" } return true; } - catch (const Exception &) + catch (const std::exception &) { log_fatal("Unable to load g2 graphics"); if (!gOpenRCT2Headless) @@ -378,7 +378,7 @@ extern "C" _csgLoaded = true; return true; } - catch (const Exception &) + catch (const std::exception &) { log_error("Unable to load csg graphics"); return false; diff --git a/src/openrct2/interface/Theme.cpp b/src/openrct2/interface/Theme.cpp index cb95d8d5d7..30d8e13676 100644 --- a/src/openrct2/interface/Theme.cpp +++ b/src/openrct2/interface/Theme.cpp @@ -16,6 +16,7 @@ #pragma warning(disable : 4706) // assignment within conditional expression +#include #include #include @@ -258,7 +259,7 @@ static const WindowThemeDesc * GetWindowThemeDescriptor(const utf8 * windowClass static void ThrowThemeLoadException() { - throw Exception("Invalid JSON UI theme entry."); + throw std::runtime_error("Invalid JSON UI theme entry."); } #pragma region UIThemeEntry @@ -412,9 +413,9 @@ bool UITheme::WriteToFile(const utf8 * path) const Json::WriteToFile(path, jsonTheme, JSON_INDENT(4) | JSON_PRESERVE_ORDER); result = true; } - catch (const Exception & ex) + catch (const std::exception & ex) { - log_error("Unable to save %s: %s", path, ex.GetMessage()); + log_error("Unable to save %s: %s", path, ex.what()); result = false; } @@ -467,7 +468,7 @@ UITheme * UITheme::FromJson(const json_t * json) return result; } - catch (const Exception &) + catch (const std::exception &) { delete result; throw; @@ -483,7 +484,7 @@ UITheme * UITheme::FromFile(const utf8 * path) json = Json::ReadFromFile(path); result = UITheme::FromJson(json); } - catch (const Exception &) + catch (const std::exception &) { log_error("Unable to read theme: %s", path); result = nullptr; diff --git a/src/openrct2/localisation/LanguagePack.cpp b/src/openrct2/localisation/LanguagePack.cpp index e2e3c916f9..3902399728 100644 --- a/src/openrct2/localisation/LanguagePack.cpp +++ b/src/openrct2/localisation/LanguagePack.cpp @@ -87,10 +87,10 @@ public: fs.Read(fileData, fileLength); fileData[fileLength] = '\0'; } - catch (const Exception &ex) + catch (const std::exception &ex) { Memory::Free(fileData); - log_error("Unable to open %s: %s", path, ex.GetMessage()); + log_error("Unable to open %s: %s", path, ex.what()); return nullptr; } diff --git a/src/openrct2/network/Network.cpp b/src/openrct2/network/Network.cpp index 4c6b7006cf..2e8dc73a1c 100644 --- a/src/openrct2/network/Network.cpp +++ b/src/openrct2/network/Network.cpp @@ -14,6 +14,7 @@ *****************************************************************************/ #pragma endregion +#include #include "../Context.h" #include "../core/Guard.hpp" #include "../OpenRCT2.h" @@ -247,7 +248,7 @@ bool Network::BeginClient(const char* host, uint16 port) auto fs = FileStream(keyPath, FILE_MODE_WRITE); _key.SavePrivate(&fs); } - catch (Exception) + catch (const std::exception &) { log_error("Unable to save private key at %s.", keyPath); return false; @@ -263,7 +264,7 @@ bool Network::BeginClient(const char* host, uint16 port) auto fs = FileStream(keyPath, FILE_MODE_WRITE); _key.SavePublic(&fs); } - catch (Exception) + catch (const std::exception &) { log_error("Unable to save public key at %s.", keyPath); return false; @@ -277,7 +278,7 @@ bool Network::BeginClient(const char* host, uint16 port) auto fs = FileStream(keyPath, FILE_MODE_OPEN); ok = _key.LoadPrivate(&fs); } - catch (Exception) + catch (const std::exception &) { log_error("Unable to read private key from %s.", keyPath); return false; @@ -312,9 +313,9 @@ bool Network::BeginServer(uint16 port, const char* address) { listening_socket->Listen(address, port); } - catch (const Exception &ex) + catch (const std::exception &ex) { - Console::Error::WriteLine(ex.GetMessage()); + Console::Error::WriteLine(ex.what()); Close(); return false; } @@ -816,9 +817,9 @@ void Network::SaveGroups() { Json::WriteToFile(path, jsonGroupsCfg, JSON_INDENT(4) | JSON_PRESERVE_ORDER); } - catch (const Exception &ex) + catch (const std::exception &ex) { - log_error("Unable to save %s: %s", path, ex.GetMessage()); + log_error("Unable to save %s: %s", path, ex.what()); } json_decref(jsonGroupsCfg); @@ -865,8 +866,8 @@ void Network::LoadGroups() if (platform_file_exists(path)) { try { json = Json::ReadFromFile(path); - } catch (const Exception &e) { - log_error("Failed to read %s as JSON. Setting default groups. %s", path, e.GetMessage()); + } catch (const std::exception &e) { + log_error("Failed to read %s as JSON. Setting default groups. %s", path, e.what()); } } @@ -929,9 +930,9 @@ void Network::AppendLog(std::ostream &fs, const std::string &s) fs.write(buffer, strlen(buffer)); } } - catch (const Exception &ex) + catch (const std::exception &ex) { - log_error("%s", ex.GetMessage()); + log_error("%s", ex.what()); } } @@ -1680,10 +1681,10 @@ void Network::Client_Handle_TOKEN(NetworkConnection& connection, NetworkPacket& auto fs = FileStream(keyPath, FILE_MODE_OPEN); if (!_key.LoadPrivate(&fs)) { - throw Exception(); + throw std::runtime_error("Failed to load private key."); } } - catch (Exception) + catch (const std::exception &) { log_error("Failed to load key %s", keyPath); connection.SetLastDisconnectReason(STR_MULTIPLAYER_VERIFICATION_FAILURE); @@ -1887,13 +1888,13 @@ void Network::Server_Handle_AUTH(NetworkConnection& connection, NetworkPacket& p const char *signature = (const char *)packet.Read(sigsize); if (signature == nullptr) { - throw Exception(); + throw std::runtime_error("Failed to read packet."); } auto ms = MemoryStream(pubkey, strlen(pubkey)); if (!connection.Key.LoadPublic(&ms)) { - throw Exception(); + throw std::runtime_error("Failed to load public key."); } bool verified = connection.Key.Verify(connection.Challenge.data(), connection.Challenge.size(), signature, sigsize); @@ -1917,7 +1918,7 @@ void Network::Server_Handle_AUTH(NetworkConnection& connection, NetworkPacket& p log_verbose("Signature verification failed!"); } } - catch (Exception) + catch (const std::exception &) { connection.AuthStatus = NETWORK_AUTH_VERIFICATIONFAILURE; log_verbose("Signature verification failed, invalid data!"); @@ -2079,7 +2080,7 @@ bool Network::LoadMap(IStream * stream) gLastAutoSaveUpdate = AUTOSAVE_PAUSE; result = true; } - catch (const Exception &) + catch (const std::exception &) { } return result; @@ -2125,7 +2126,7 @@ bool Network::SaveMap(IStream * stream, const std::vectormaxplayers = 0; } } - catch (const Exception &) + catch (const std::exception &) { Memory::FreeArray(entries, numEntries); numEntries = 0; @@ -88,7 +88,7 @@ extern "C" } return true; } - catch (const Exception &) + catch (const std::exception &) { return false; } diff --git a/src/openrct2/network/TcpSocket.cpp b/src/openrct2/network/TcpSocket.cpp index 03a3364c14..7f95ab865b 100644 --- a/src/openrct2/network/TcpSocket.cpp +++ b/src/openrct2/network/TcpSocket.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #ifdef _WIN32 @@ -26,7 +27,6 @@ #include #include - #undef GetMessage #define LAST_SOCKET_ERROR() WSAGetLastError() #undef EWOULDBLOCK #define EWOULDBLOCK WSAEWOULDBLOCK @@ -59,7 +59,6 @@ #endif // defined(__linux__) #endif // _WIN32 -#include "../core/Exception.hpp" #include "TcpSocket.h" constexpr auto CONNECT_TIMEOUT = std::chrono::milliseconds(3000); @@ -70,11 +69,10 @@ constexpr auto CONNECT_TIMEOUT = std::chrono::milliseconds(3000); class TcpSocket; -class SocketException : public Exception +class SocketException : public std::runtime_error { public: - explicit SocketException(const char * message) : Exception(message) { } - explicit SocketException(const std::string &message) : Exception(message) { } + explicit SocketException(const std::string &message) : std::runtime_error(message) { } }; class TcpSocket final : public ITcpSocket @@ -121,7 +119,7 @@ public: { if (_status != SOCKET_STATUS_CLOSED) { - throw Exception("Socket not closed."); + throw std::runtime_error("Socket not closed."); } sockaddr_storage ss; @@ -168,7 +166,7 @@ public: throw SocketException("Failed to set non-blocking mode."); } } - catch (const Exception &) + catch (const std::exception &) { CloseSocket(); throw; @@ -182,7 +180,7 @@ public: { if (_status != SOCKET_STATUS_LISTENING) { - throw Exception("Socket not listening."); + throw std::runtime_error("Socket not listening."); } struct sockaddr_storage client_addr; socklen_t client_len = sizeof(struct sockaddr_storage); @@ -229,7 +227,7 @@ public: { if (_status != SOCKET_STATUS_CLOSED) { - throw Exception("Socket not closed."); + throw std::runtime_error("Socket not closed."); } try @@ -311,7 +309,7 @@ public: // Connection request timed out throw SocketException("Connection timed out."); } - catch (const Exception &) + catch (const std::exception &) { CloseSocket(); throw; @@ -322,7 +320,7 @@ public: { if (_status != SOCKET_STATUS_CLOSED) { - throw Exception("Socket not closed."); + throw std::runtime_error("Socket not closed."); } auto saddress = std::string(address); @@ -334,9 +332,9 @@ public: { Connect(saddress.c_str(), port); } - catch (const Exception &ex) + catch (const std::exception &ex) { - _error = std::string(ex.GetMessage()); + _error = std::string(ex.what()); } barrier2.set_value(); }, std::move(barrier)); @@ -355,7 +353,7 @@ public: { if (_status != SOCKET_STATUS_CONNECTED) { - throw Exception("Socket not connected."); + throw std::runtime_error("Socket not connected."); } size_t totalSent = 0; @@ -377,7 +375,7 @@ public: { if (_status != SOCKET_STATUS_CONNECTED) { - throw Exception("Socket not connected."); + throw std::runtime_error("Socket not connected."); } sint32 readBytes = recv(_socket, (char *)buffer, (sint32)size, 0); diff --git a/src/openrct2/object/ImageTable.cpp b/src/openrct2/object/ImageTable.cpp index 824bb12897..793c0f8309 100644 --- a/src/openrct2/object/ImageTable.cpp +++ b/src/openrct2/object/ImageTable.cpp @@ -14,6 +14,7 @@ *****************************************************************************/ #pragma endregion +#include #include "../core/IStream.hpp" #include "../core/Memory.hpp" #include "../OpenRCT2.h" @@ -52,7 +53,7 @@ void ImageTable::Read(IReadObjectContext * context, IStream * stream) if (_data == nullptr) { context->LogError(OBJECT_ERROR_BAD_IMAGE_TABLE, "Image table too large."); - throw Exception(); + throw std::runtime_error("Image table too large."); } // Read g1 element headers @@ -89,7 +90,7 @@ void ImageTable::Read(IReadObjectContext * context, IStream * stream) // TODO validate the image data to prevent crashes in-game } - catch (const Exception &) + catch (const std::exception &) { context->LogError(OBJECT_ERROR_BAD_IMAGE_TABLE, "Bad image table."); throw; diff --git a/src/openrct2/object/ObjectFactory.cpp b/src/openrct2/object/ObjectFactory.cpp index d5ef899ad0..854be09457 100644 --- a/src/openrct2/object/ObjectFactory.cpp +++ b/src/openrct2/object/ObjectFactory.cpp @@ -93,7 +93,7 @@ namespace ObjectFactory // TODO check that ex is really EOF and not some other error context->LogError(OBJECT_ERROR_UNEXPECTED_EOF, "Unexpectedly reached end of file."); } - catch (const Exception &) + catch (const std::exception &) { context->LogError(OBJECT_ERROR_UNKNOWN, nullptr); } @@ -124,10 +124,10 @@ namespace ObjectFactory ReadObjectLegacy(result, &readContext, &chunkStream); if (readContext.WasError()) { - throw Exception("Object has errors"); + throw std::runtime_error("Object has errors"); } } - catch (Exception) + catch (const std::exception &) { Console::Error::WriteLine("Unable to open or read '%s'", path); @@ -200,7 +200,7 @@ namespace ObjectFactory result = new StexObject(entry); break; default: - throw Exception("Invalid object type"); + throw std::runtime_error("Invalid object type"); } return result; } diff --git a/src/openrct2/object/ObjectRepository.cpp b/src/openrct2/object/ObjectRepository.cpp index 681a34ef55..f706d129cb 100644 --- a/src/openrct2/object/ObjectRepository.cpp +++ b/src/openrct2/object/ObjectRepository.cpp @@ -303,7 +303,7 @@ public: SaveObject(path, objectEntry, data, dataSize); ScanObject(path); } - catch (const Exception &) + catch (const std::exception &) { Console::Error::WriteLine("Failed saving object: [%s] to '%s'.", objectName, path); } @@ -487,7 +487,7 @@ private: Memory::Free(newData); Memory::Free(extraBytes); } - catch (const Exception &) + catch (const std::exception &) { Memory::Free(newData); Memory::Free(extraBytes); @@ -514,7 +514,7 @@ private: Memory::Free(encodedDataBuffer); } - catch (const Exception &) + catch (const std::exception &) { Memory::Free(encodedDataBuffer); throw; @@ -591,7 +591,7 @@ private: const ObjectRepositoryItem * item = FindObject(entry); if (item == nullptr) { - throw Exception(String::StdFormat("Unable to find object '%.8s'", entry->name)); + throw std::runtime_error(String::StdFormat("Unable to find object '%.8s'", entry->name)); } // Read object data from file @@ -599,7 +599,7 @@ private: auto fileEntry = fs.ReadValue(); if (!object_entry_compare(entry, &fileEntry)) { - throw Exception("Header found in object file does not match object to pack."); + throw std::runtime_error("Header found in object file does not match object to pack."); } auto chunkReader = SawyerChunkReader(&fs); auto chunk = chunkReader.ReadChunk(); diff --git a/src/openrct2/object/StringTable.cpp b/src/openrct2/object/StringTable.cpp index d1fc9f14d4..6884b72dae 100644 --- a/src/openrct2/object/StringTable.cpp +++ b/src/openrct2/object/StringTable.cpp @@ -80,7 +80,7 @@ void StringTable::Read(IReadObjectContext * context, IStream * stream, uint8 id) _strings.push_back(entry); } } - catch (const Exception &) + catch (const std::exception &) { context->LogError(OBJECT_ERROR_BAD_STRING_TABLE, "Bad string table."); throw; diff --git a/src/openrct2/platform/Crash.cpp b/src/openrct2/platform/Crash.cpp index 514beb34ea..96b4076772 100644 --- a/src/openrct2/platform/Crash.cpp +++ b/src/openrct2/platform/Crash.cpp @@ -36,7 +36,6 @@ extern "C" } #include "../core/Console.hpp" -#include "../core/Exception.hpp" #include "../rct2/S6Exporter.h" #include "../Version.h" @@ -99,7 +98,7 @@ static bool OnCrash(const wchar_t * dumpPath, exporter->SaveGame(saveFilePathUTF8); savedGameDumped = true; } - catch (const Exception &) + catch (const std::exception &) { } free(saveFilePathUTF8); diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index 36107b44f2..08b2ca8f72 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -18,7 +18,6 @@ #include #include "../core/Collections.hpp" #include "../core/Console.hpp" -#include "../core/Exception.hpp" #include "../core/FileStream.hpp" #include "../core/Guard.hpp" #include "../core/IStream.hpp" @@ -141,7 +140,7 @@ public: } else { - throw Exception("Invalid RCT1 park extension."); + throw std::runtime_error("Invalid RCT1 park extension."); } } @@ -202,7 +201,7 @@ public: } else { - throw Exception("Unable to decode park."); + throw std::runtime_error("Unable to decode park."); } return ParkLoadResult::CreateOK(); } @@ -1829,7 +1828,7 @@ private: if (object == nullptr && objectType != OBJECT_TYPE_SCENERY_GROUP) { log_error("Failed to load %s.", objectName); - throw Exception("Failed to load object."); + throw std::runtime_error("Failed to load object."); } entryIndex++; @@ -2746,7 +2745,7 @@ extern "C" s4Importer->Import(); } } - catch (const Exception &) + catch (const std::exception &) { delete result; result = new ParkLoadResult(ParkLoadResult::CreateUnknown()); @@ -2766,7 +2765,7 @@ extern "C" s4Importer->Import(); } } - catch (const Exception &) + catch (const std::exception &) { delete result; result = new ParkLoadResult(ParkLoadResult::CreateUnknown()); diff --git a/src/openrct2/rct12/SawyerChunkReader.cpp b/src/openrct2/rct12/SawyerChunkReader.cpp index 629f77069d..67305db8ba 100644 --- a/src/openrct2/rct12/SawyerChunkReader.cpp +++ b/src/openrct2/rct12/SawyerChunkReader.cpp @@ -14,7 +14,6 @@ *****************************************************************************/ #pragma endregion -#include "../core/Exception.hpp" #include "../core/IStream.hpp" #include "../core/Math.hpp" #include "../core/Memory.hpp" @@ -48,7 +47,7 @@ void SawyerChunkReader::SkipChunk() auto header = _stream->ReadValue(); _stream->Seek(header.length, STREAM_SEEK_CURRENT); } - catch (Exception) + catch (const std::exception &) { // Rewind stream back to original position _stream->SetPosition(originalPosition); @@ -79,7 +78,7 @@ std::shared_ptr SawyerChunkReader::ReadChunk() uint8 * buffer = Memory::Allocate(bufferSize); if (buffer == nullptr) { - throw Exception("Unable to allocate buffer."); + throw std::runtime_error("Unable to allocate buffer."); } size_t uncompressedLength = DecodeChunk(buffer, bufferSize, compressedData.get(), header); @@ -87,7 +86,7 @@ std::shared_ptr SawyerChunkReader::ReadChunk() buffer = Memory::Reallocate(buffer, uncompressedLength); if (buffer == nullptr) { - throw Exception("Unable to reallocate buffer."); + throw std::runtime_error("Unable to reallocate buffer."); } return std::make_shared((SAWYER_ENCODING)header.encoding, buffer, uncompressedLength); @@ -96,7 +95,7 @@ std::shared_ptr SawyerChunkReader::ReadChunk() throw SawyerChunkException(EXCEPTION_MSG_INVALID_CHUNK_ENCODING); } } - catch (Exception) + catch (const std::exception &) { // Rewind stream back to original position _stream->SetPosition(originalPosition); diff --git a/src/openrct2/rct12/SawyerChunkWriter.cpp b/src/openrct2/rct12/SawyerChunkWriter.cpp index 4853b1b49f..5cfad2fd70 100644 --- a/src/openrct2/rct12/SawyerChunkWriter.cpp +++ b/src/openrct2/rct12/SawyerChunkWriter.cpp @@ -14,7 +14,6 @@ *****************************************************************************/ #pragma endregion -#include "../core/Exception.hpp" #include "../core/IStream.hpp" #include "../core/Math.hpp" #include "SawyerChunkWriter.h" diff --git a/src/openrct2/rct12/SawyerEncoding.cpp b/src/openrct2/rct12/SawyerEncoding.cpp index 32602035bf..dda1ff6dfa 100644 --- a/src/openrct2/rct12/SawyerEncoding.cpp +++ b/src/openrct2/rct12/SawyerEncoding.cpp @@ -56,7 +56,7 @@ namespace SawyerEncoding stream->SetPosition(initialPosition); return checksum == fileChecksum; } - catch (Exception) + catch (const std::exception &) { // Rewind back to original position stream->SetPosition(initialPosition); diff --git a/src/openrct2/rct2/S6Exporter.cpp b/src/openrct2/rct2/S6Exporter.cpp index acd609f4a6..3be7f3eab9 100644 --- a/src/openrct2/rct2/S6Exporter.cpp +++ b/src/openrct2/rct2/S6Exporter.cpp @@ -14,7 +14,6 @@ *****************************************************************************/ #pragma endregion -#include "../core/Exception.hpp" #include "../core/FileStream.hpp" #include "../core/IStream.hpp" #include "../core/String.hpp" @@ -737,7 +736,7 @@ extern "C" } result = true; } - catch (const Exception &) + catch (const std::exception &) { } delete s6exporter; diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index 5f9d972df4..4c5aec5a5c 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -15,7 +15,6 @@ #pragma endregion #include "../core/Console.hpp" -#include "../core/Exception.hpp" #include "../core/FileStream.hpp" #include "../core/IStream.hpp" #include "../core/Path.hpp" @@ -50,11 +49,11 @@ #include "../world/map_animation.h" #include "../world/Park.h" -class ObjectLoadException : public Exception +class ObjectLoadException : public std::runtime_error { public: - ObjectLoadException() : Exception("Unable to load objects.") { } - explicit ObjectLoadException(const char * message) : Exception(message) { } + ObjectLoadException() : std::runtime_error("Unable to load objects.") { } + explicit ObjectLoadException(const std::string &message) : std::runtime_error(message) { } }; /** @@ -91,7 +90,7 @@ public: } else { - throw Exception("Invalid RCT2 park extension."); + throw std::runtime_error("Invalid RCT2 park extension."); } } @@ -129,7 +128,7 @@ public: { if (_s6.header.type != S6_TYPE_SCENARIO) { - throw Exception("Park is not a scenario."); + throw std::runtime_error("Park is not a scenario."); } chunkReader.ReadChunk(&_s6.info, sizeof(_s6.info)); } @@ -137,7 +136,7 @@ public: { if (_s6.header.type != S6_TYPE_SAVEDGAME) { - throw Exception("Park is not a saved game."); + throw std::runtime_error("Park is not a saved game."); } } @@ -818,7 +817,7 @@ extern "C" gErrorType = ERROR_TYPE_FILE_LOAD; gErrorStringId = STR_GAME_SAVE_FAILED; } - catch (const Exception &) + catch (const std::exception &) { gErrorType = ERROR_TYPE_FILE_LOAD; gErrorStringId = STR_FILE_CONTAINS_INVALID_DATA; @@ -867,7 +866,7 @@ extern "C" gErrorType = ERROR_TYPE_FILE_LOAD; gErrorStringId = STR_GAME_SAVE_FAILED; } - catch (const Exception &) + catch (const std::exception &) { gErrorType = ERROR_TYPE_FILE_LOAD; gErrorStringId = STR_FILE_CONTAINS_INVALID_DATA; diff --git a/src/openrct2/scenario/ScenarioRepository.cpp b/src/openrct2/scenario/ScenarioRepository.cpp index 3b3c289b9a..eaa6dc4893 100644 --- a/src/openrct2/scenario/ScenarioRepository.cpp +++ b/src/openrct2/scenario/ScenarioRepository.cpp @@ -225,7 +225,7 @@ private: result = true; } } - catch (Exception) + catch (const std::exception &) { } return result; @@ -249,7 +249,7 @@ private: } } } - catch (Exception) + catch (const std::exception &) { Console::Error::WriteLine("Unable to read scenario: '%s'", path.c_str()); } @@ -588,7 +588,7 @@ private: highscore->timestamp = fs.ReadValue(); } } - catch (const Exception &) + catch (const std::exception &) { Console::Error::WriteLine("Error reading highscores."); } @@ -662,7 +662,7 @@ private: } } } - catch (const Exception &) + catch (const std::exception &) { Console::Error::WriteLine("Error reading legacy scenario scores file: '%s'", path.c_str()); } @@ -719,7 +719,7 @@ private: fs.WriteValue(highscore->timestamp); } } - catch (const Exception &) + catch (const std::exception &) { Console::Error::WriteLine("Unable to save highscores to '%s'", path.c_str()); } diff --git a/src/openrct2/title/TitleSequence.cpp b/src/openrct2/title/TitleSequence.cpp index 094d885729..ea9c6ba424 100644 --- a/src/openrct2/title/TitleSequence.cpp +++ b/src/openrct2/title/TitleSequence.cpp @@ -161,7 +161,7 @@ extern "C" } catch (const IOException& exception) { - Console::Error::WriteLine(exception.GetMessage()); + Console::Error::WriteLine(exception.what()); } if (fileStream != nullptr) @@ -208,7 +208,7 @@ extern "C" fs.Write(script, String::SizeOf(script)); success = true; } - catch (Exception) + catch (const std::exception &) { } } @@ -255,9 +255,9 @@ extern "C" delete zip; Memory::Free(fdata); } - catch (const Exception &ex) + catch (const std::exception &ex) { - Console::Error::WriteLine(ex.GetMessage()); + Console::Error::WriteLine(ex.what()); } } else @@ -580,7 +580,7 @@ static void * ReadScriptFile(const utf8 * path, size_t * outSize) buffer = Memory::Allocate(size); fs.Read(buffer, size); } - catch (Exception) + catch (const std::exception &) { Memory::Free(buffer); buffer = nullptr; diff --git a/src/openrct2/title/TitleSequencePlayer.cpp b/src/openrct2/title/TitleSequencePlayer.cpp index 6e1a06cd0f..aef9a38d53 100644 --- a/src/openrct2/title/TitleSequencePlayer.cpp +++ b/src/openrct2/title/TitleSequencePlayer.cpp @@ -18,7 +18,6 @@ #include "../common.h" #include "../Context.h" #include "../core/Console.hpp" -#include "../core/Exception.hpp" #include "../core/Guard.hpp" #include "../core/Math.hpp" #include "../core/Path.hpp" @@ -180,7 +179,7 @@ public: { if (targetPosition < 0 || targetPosition >= (sint32)_sequence->NumCommands) { - throw Exception("Invalid position."); + throw std::runtime_error("Invalid position."); } if (_position >= targetPosition) { @@ -421,7 +420,7 @@ private: PrepareParkForPlayback(); success = true; } - catch (Exception) + catch (const std::exception &) { Console::Error::WriteLine("Unable to load park: %s", path); } @@ -456,7 +455,7 @@ private: PrepareParkForPlayback(); success = true; } - catch (Exception) + catch (const std::exception &) { Console::Error::WriteLine("Unable to load park: %s", hintPath.c_str()); }