diff --git a/src/common/FSNodeZIP.cxx b/src/common/FSNodeZIP.cxx index 09116c9aa..774feee44 100644 --- a/src/common/FSNodeZIP.cxx +++ b/src/common/FSNodeZIP.cxx @@ -180,9 +180,9 @@ uInt32 FilesystemNodeZIP::read(uInt8*& image) const switch(_error) { case ZIPERR_NONE: break; - case ZIPERR_NOT_A_FILE: throw "ZIP file contains errors/not found"; - case ZIPERR_NOT_READABLE: throw "ZIP file not readable"; - case ZIPERR_NO_ROMS: throw "ZIP file doesn't contain any ROMs"; + case ZIPERR_NOT_A_FILE: throw runtime_error("ZIP file contains errors/not found"); + case ZIPERR_NOT_READABLE: throw runtime_error("ZIP file not readable"); + case ZIPERR_NO_ROMS: throw runtime_error("ZIP file doesn't contain any ROMs"); } ZipHandler& zip = open(_zipFile); diff --git a/src/common/FrameBufferSDL2.cxx b/src/common/FrameBufferSDL2.cxx index 4dfde322a..37f4a15f7 100644 --- a/src/common/FrameBufferSDL2.cxx +++ b/src/common/FrameBufferSDL2.cxx @@ -46,7 +46,7 @@ FrameBufferSDL2::FrameBufferSDL2(OSystem& osystem) ostringstream buf; buf << "ERROR: Couldn't initialize SDL: " << SDL_GetError() << endl; myOSystem.logMessage(buf.str(), 0); - throw "FATAL ERROR"; + throw runtime_error("FATAL ERROR"); } myOSystem.logMessage("FrameBufferSDL2::FrameBufferSDL2 SDL_Init()", 2); diff --git a/src/common/PNGLibrary.cxx b/src/common/PNGLibrary.cxx index 8646ed99a..dcbef1a4b 100644 --- a/src/common/PNGLibrary.cxx +++ b/src/common/PNGLibrary.cxx @@ -123,7 +123,7 @@ done: png_destroy_read_struct(&png_ptr, info_ptr ? &info_ptr : (png_infopp)0, (png_infopp)0); if(err_message) - throw err_message; + throw runtime_error(err_message); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -131,7 +131,7 @@ void PNGLibrary::saveImage(const string& filename, const VariantList& comments) { ofstream out(filename, ios_base::binary); if(!out.is_open()) - throw "ERROR: Couldn't create snapshot file"; + throw runtime_error("ERROR: Couldn't create snapshot file"); const GUI::Rect& rect = myFB.imageRect(); png_uint_32 width = rect.width(), height = rect.height(); @@ -155,7 +155,7 @@ void PNGLibrary::saveImage(const string& filename, const FBSurface& surface, { ofstream out(filename, ios_base::binary); if(!out.is_open()) - throw "ERROR: Couldn't create snapshot file"; + throw runtime_error("ERROR: Couldn't create snapshot file"); // Do we want the entire surface or just a section? png_uint_32 width = rect.width(), height = rect.height(); @@ -240,7 +240,7 @@ done: if (rows) delete[] rows; if(err_message) - throw err_message; + throw runtime_error(err_message); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -338,22 +338,19 @@ void PNGLibrary::png_write_data(png_structp ctx, png_bytep area, png_size_t size // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void PNGLibrary::png_io_flush(png_structp ctx) { - ofstream* stream = (ofstream *) png_get_io_ptr(ctx); - stream->flush(); + ((ofstream *) png_get_io_ptr(ctx))->flush(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void PNGLibrary::png_user_warn(png_structp ctx, png_const_charp str) { - const string& msg = string("PNGLibrary warning: ") + str; - throw msg.c_str(); + throw runtime_error(string("PNGLibrary warning: ") + str); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void PNGLibrary::png_user_error(png_structp ctx, png_const_charp str) { - const string& msg = string("PNGLibrary error: ") + str; - throw msg.c_str(); + throw runtime_error(string("PNGLibrary error: ") + str); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/common/PNGLibrary.hxx b/src/common/PNGLibrary.hxx index 3def9fab9..eb10dc371 100644 --- a/src/common/PNGLibrary.hxx +++ b/src/common/PNGLibrary.hxx @@ -51,20 +51,21 @@ class PNGLibrary @param surface The FBSurface into which to place the PNG data @return On success, the FBSurface containing image data, otherwise a - const char* exception is thrown containing a more detailed + runtime_error is thrown containing a more detailed error message. */ void loadImage(const string& filename, FBSurface& surface); /** - Save the current FrameBuffer image to a PNG file. Note that in most cases - this will be a TIA image, but it could actually be used for *any* mode. + Save the current FrameBuffer image to a PNG file. Note that in most + cases this will be a TIA image, but it could actually be used for + *any* mode. @param filename The filename to save the PNG image @param comments The text comments to add to the PNG image @return On success, the PNG file has been saved to 'filename', - otherwise a const char* exception is thrown containing a + otherwise a runtime_error is thrown containing a more detailed error message. */ void saveImage(const string& filename, @@ -79,7 +80,7 @@ class PNGLibrary @param comments The text comments to add to the PNG image @return On success, the PNG file has been saved to 'filename', - otherwise a const char* exception is thrown containing a + otherwise a runtime_error is thrown containing a more detailed error message. */ void saveImage(const string& filename, const FBSurface& surface, diff --git a/src/common/ZipHandler.cxx b/src/common/ZipHandler.cxx index 7268d750e..40a99ba88 100644 --- a/src/common/ZipHandler.cxx +++ b/src/common/ZipHandler.cxx @@ -113,11 +113,11 @@ uInt32 ZipHandler::decompress(uInt8*& image) { delete[] image; image = nullptr; - throw zip_error_s[err]; + throw runtime_error(zip_error_s[err]); } } else - throw "Invalid ZIP archive"; + throw runtime_error("Invalid ZIP archive"); } /*------------------------------------------------- diff --git a/src/debugger/gui/PromptWidget.cxx b/src/debugger/gui/PromptWidget.cxx index 18120d691..b44e68ecc 100644 --- a/src/debugger/gui/PromptWidget.cxx +++ b/src/debugger/gui/PromptWidget.cxx @@ -495,11 +495,11 @@ void PromptWidget::loadConfig() { // Display greetings & prompt string version = string("Stella ") + STELLA_VERSION + "\n"; - print(version.c_str()); + print(version); print(PROMPT); // Take care of one-time debugger stuff - print(instance().debugger().autoExec().c_str()); + print(instance().debugger().autoExec()); print(instance().debugger().cartDebug().loadConfigFile() + "\n"); print(instance().debugger().cartDebug().loadListFile() + "\n"); print(instance().debugger().cartDebug().loadSymbolFile() + "\n"); diff --git a/src/debugger/gui/TiaOutputWidget.cxx b/src/debugger/gui/TiaOutputWidget.cxx index 6dbdf7c0b..f2b37e5ae 100644 --- a/src/debugger/gui/TiaOutputWidget.cxx +++ b/src/debugger/gui/TiaOutputWidget.cxx @@ -82,9 +82,9 @@ void TiaOutputWidget::saveSnapshot() { instance().png().saveImage(sspath.str(), s, rect); } - catch(const char* msg) + catch(const runtime_error& e) { - message = msg; + message = e.what(); } instance().frameBuffer().showMessage(message); } diff --git a/src/emucore/Cart.cxx b/src/emucore/Cart.cxx index 63f596e69..b65ba03c0 100644 --- a/src/emucore/Cart.cxx +++ b/src/emucore/Cart.cxx @@ -257,15 +257,9 @@ Cartridge* Cartridge::create(const uInt8* image, uInt32 size, string& md5, else if(type == "X07") cartridge = new CartridgeX07(image, size, settings); else if(dtype == "WRONG_SIZE") - { - string err = "Invalid cart size for type '" + type + "'"; - throw err.c_str(); - } + throw runtime_error("Invalid cart size for type '" + type + "'"); else - { - string err = "Invalid cart type '" + type + "'"; - throw err.c_str(); - } + throw runtime_error("Invalid cart type '" + type + "'"); if(size < 1024) buf << " (" << size << "B) "; diff --git a/src/emucore/CartDPCPlus.cxx b/src/emucore/CartDPCPlus.cxx index 92a20b87b..9809d01ba 100644 --- a/src/emucore/CartDPCPlus.cxx +++ b/src/emucore/CartDPCPlus.cxx @@ -199,13 +199,13 @@ inline void CartridgeDPCPlus::callFunction(uInt8 value) try { myThumbEmulator->run(); } - catch(const string& error) { + catch(const runtime_error& e) { if(!mySystem->autodetectMode()) { #ifdef DEBUGGER_SUPPORT - Debugger::debugger().startWithFatalError(error); + Debugger::debugger().startWithFatalError(e.what()); #else - cout << error << endl; + cout << e.what() << endl; #endif } } diff --git a/src/emucore/EventHandler.cxx b/src/emucore/EventHandler.cxx index 46de507d1..9f06445e4 100644 --- a/src/emucore/EventHandler.cxx +++ b/src/emucore/EventHandler.cxx @@ -1781,9 +1781,9 @@ void EventHandler::takeSnapshot(uInt32 number) const FBSurface& surface = myOSystem.frameBuffer().tiaSurface().baseSurface(rect); myOSystem.png().saveImage(filename, surface, rect, comments); } - catch(const char* msg) + catch(const runtime_error& e) { - message = msg; + message = e.what(); } if(showmessage) myOSystem.frameBuffer().showMessage(message); @@ -1798,9 +1798,9 @@ void EventHandler::takeSnapshot(uInt32 number) { myOSystem.png().saveImage(filename, comments); } - catch(const char* msg) + catch(const runtime_error& e) { - message = msg; + message = e.what(); } // Re-enable old messages diff --git a/src/emucore/FSNode.cxx b/src/emucore/FSNode.cxx index a74a43240..903e97f0f 100644 --- a/src/emucore/FSNode.cxx +++ b/src/emucore/FSNode.cxx @@ -185,7 +185,7 @@ uInt32 FilesystemNode::read(uInt8*& image) const // File must actually exist if(!(exists() && isReadable())) - throw "File not found/readable"; + throw runtime_error("File not found/readable"); // Otherwise, assume the file is either gzip'ed or not compressed at all gzFile f = gzopen(getPath().c_str(), "rb"); @@ -198,10 +198,10 @@ uInt32 FilesystemNode::read(uInt8*& image) const if(size == 0) { delete[] image; image = nullptr; - throw "Zero-byte file"; + throw runtime_error("Zero-byte file"); } return size; } else - throw "ZLIB open/read error"; + throw runtime_error("ZLIB open/read error"); } diff --git a/src/emucore/OSystem.cxx b/src/emucore/OSystem.cxx index ce5421556..3bb29b26c 100644 --- a/src/emucore/OSystem.cxx +++ b/src/emucore/OSystem.cxx @@ -314,9 +314,9 @@ string OSystem::createConsole(const FilesystemNode& rom, const string& md5sum, closeConsole(); myConsole = openConsole(myRomFile, myRomMD5, type, id); } - catch(const char* err_msg) + catch(const runtime_error& e) { - buf << "ERROR: Couldn't create console (" << err_msg << ")"; + buf << "ERROR: Couldn't create console (" << e.what() << ")"; logMessage(buf.str(), 0); return buf.str(); } @@ -439,10 +439,10 @@ string OSystem::getROMInfo(const FilesystemNode& romfile) { console = openConsole(romfile, md5, type, id); } - catch(const char* err_msg) + catch(const runtime_error& e) { ostringstream buf; - buf << "ERROR: Couldn't get ROM info (" << err_msg << ")"; + buf << "ERROR: Couldn't get ROM info (" << e.what() << ")"; return buf.str(); } diff --git a/src/emucore/Thumbulator.cxx b/src/emucore/Thumbulator.cxx index 47d80b821..782eae8f7 100644 --- a/src/emucore/Thumbulator.cxx +++ b/src/emucore/Thumbulator.cxx @@ -68,7 +68,7 @@ string Thumbulator::run( void ) { if (execute()) break; if (instructions > 500000) // way more than would otherwise be possible - throw "instructions > 500000"; + throw runtime_error("instructions > 500000"); } #if defined(THUMB_DISS) || defined(THUMB_DBUG) dump_counters(); @@ -84,7 +84,7 @@ inline int Thumbulator::fatalError(const char* opcode, uInt32 v1, const char* ms << opcode << "(" << Base::HEX8 << v1 << "), " << msg << endl; dump_regs(); if(trapOnFatal) - throw statusMsg.str(); + throw runtime_error(statusMsg.str()); return 0; } @@ -96,7 +96,7 @@ inline int Thumbulator::fatalError(const char* opcode, uInt32 v1, uInt32 v2, << opcode << "(" << Base::HEX8 << v1 << "," << v2 << "), " << msg << endl; dump_regs(); if(trapOnFatal) - throw statusMsg.str(); + throw runtime_error(statusMsg.str()); return 0; } @@ -239,7 +239,7 @@ void Thumbulator::write32 ( uInt32 addr, uInt32 data ) { case 0xF0000000: //halt dump_counters(); - throw "HALT";// exit(0); + throw runtime_error("HALT");// exit(0); case 0xE0000000: //periph switch(addr) diff --git a/src/emucore/Thumbulator.hxx b/src/emucore/Thumbulator.hxx index 68f71e33e..03f904189 100644 --- a/src/emucore/Thumbulator.hxx +++ b/src/emucore/Thumbulator.hxx @@ -66,7 +66,7 @@ class Thumbulator ~Thumbulator(); /** - Run the ARM code, and return when finished. A string exception is + Run the ARM code, and return when finished. A runtime_error exception is thrown in case of any fatal errors/aborts (if enabled), containing the actual error, and the contents of the registers at that point in time. @@ -107,8 +107,8 @@ class Thumbulator void do_cflag_bit ( uInt32 x ); void do_vflag_bit ( uInt32 x ); - // Throw a string exception containing an error referencing the given - // message and variables + // Throw a runtime_error exception containing an error referencing the + // given message and variables // Note that the return value is never used in these methods int fatalError(const char* opcode, uInt32 v1, const char* msg); int fatalError(const char* opcode, uInt32 v1, uInt32 v2, const char* msg); diff --git a/src/gui/RomInfoWidget.cxx b/src/gui/RomInfoWidget.cxx index c96a4909c..87c3d0375 100644 --- a/src/gui/RomInfoWidget.cxx +++ b/src/gui/RomInfoWidget.cxx @@ -108,10 +108,10 @@ void RomInfoWidget::parseProperties() float scale = BSPF_min(float(myAvail.w) / src.width(), float(myAvail.h) / src.height()); mySurface->setDstSize(uInt32(src.width() * scale), uInt32(src.height() * scale)); } - catch(const char* msg) + catch(const runtime_error& e) { mySurfaceIsValid = false; - mySurfaceErrorMsg = msg; + mySurfaceErrorMsg = e.what(); } if(mySurface) mySurface->setVisible(mySurfaceIsValid);