In my never-ending attempt to eliminate pointers whereever possible,

change all throws of 'const char*' to runtime_error.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@3168 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2015-06-12 20:44:09 +00:00
parent 99f88719e5
commit c5819cae46
15 changed files with 48 additions and 56 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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