throw std::runtime_error instead of std::string (PR #1011)

+ add more information about location of yaml parser error.
This commit is contained in:
Andrea 2021-12-18 16:37:28 +00:00 committed by GitHub
parent 651b57fdae
commit 47f721882e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 113 additions and 115 deletions

View File

@ -1105,7 +1105,7 @@ bool CAY8910::LoadSnapshot(YamlLoadHelper& yamlLoadHelper, const std::string& su
{
std::string unit = std::string(SS_YAML_KEY_AY8910) + suffix;
if (!yamlLoadHelper.GetSubMap(unit))
throw std::string("Card: Expected key: ") + unit;
throw std::runtime_error("Card: Expected key: " + unit);
ay_tone_tick[0] = yamlLoadHelper.LoadUint(SS_YAML_KEY_TONE0_TICK);
ay_tone_tick[1] = yamlLoadHelper.LoadUint(SS_YAML_KEY_TONE1_TICK);
@ -1130,7 +1130,7 @@ bool CAY8910::LoadSnapshot(YamlLoadHelper& yamlLoadHelper, const std::string& su
env_counter = yamlLoadHelper.LoadUint(SS_YAML_KEY_ENV_COUNTER);
if (!yamlLoadHelper.GetSubMap(SS_YAML_KEY_REGISTERS))
throw std::string("Card: Expected key: ") + SS_YAML_KEY_REGISTERS;
throw std::runtime_error("Card: Expected key: " SS_YAML_KEY_REGISTERS);
USHORT period = (USHORT) yamlLoadHelper.LoadUint(SS_YAML_KEY_REG_TONE0_PERIOD);
sound_ay_registers[0] = period & 0xff;
@ -1174,7 +1174,7 @@ bool CAY8910::LoadSnapshot(YamlLoadHelper& yamlLoadHelper, const std::string& su
unsigned int _val = 0;
if(4 != sscanf_s(value.c_str(), SS_YAML_VALUE_CHANGE_FORMAT,
&_tstates, &_ofs, &_reg, &_val))
throw std::string("Card: AY8910: Failed to scanf change list");
throw std::runtime_error("Card: AY8910: Failed to scanf change list");
ay_change[ay_change_count].tstates = _tstates;
ay_change[ay_change_count].ofs = _ofs;
@ -1183,7 +1183,7 @@ bool CAY8910::LoadSnapshot(YamlLoadHelper& yamlLoadHelper, const std::string& su
ay_change_count++;
if (ay_change_count > AY_CHANGE_MAX)
throw std::string("Card: AY8910: Too many changes");
throw std::runtime_error("Card: AY8910: Too many changes");
}
yamlLoadHelper.PopMap();

View File

@ -810,7 +810,7 @@ void CpuLoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT version)
eCpuType cpu;
if (cpuType == SS_YAML_VALUE_6502) cpu = CPU_6502;
else if (cpuType == SS_YAML_VALUE_65C02) cpu = CPU_65C02;
else throw std::string("Load: Unknown main CPU type");
else throw std::runtime_error("Load: Unknown main CPU type");
SetMainCpu(cpu);
regs.a = (BYTE) yamlLoadHelper.LoadUint(SS_YAML_KEY_REGA);

View File

@ -61,7 +61,7 @@ Disk2InterfaceCard::Disk2InterfaceCard(UINT slot) :
Card(CT_Disk2, slot)
{
if (m_slot != 5 && m_slot != 6) // fixme
throw std::string("Card: wrong slot");
throw std::runtime_error("Card: wrong slot");
ResetSwitches();
@ -2095,7 +2095,7 @@ bool Disk2InterfaceCard::LoadSnapshotFloppy(YamlLoadHelper& yamlLoadHelper, UINT
m_floppyDrive[unit].m_disk.m_extraCycles = yamlLoadHelper.LoadDouble(SS_YAML_KEY_EXTRA_CYCLES);
if (m_floppyDrive[unit].m_disk.m_bitCount && (m_floppyDrive[unit].m_disk.m_bitOffset >= m_floppyDrive[unit].m_disk.m_bitCount))
throw std::string("Disk image: bitOffset >= bitCount");
throw std::runtime_error("Disk image: bitOffset >= bitCount");
if (ImageIsWOZ(m_floppyDrive[unit].m_disk.m_imagehandle))
UpdateBitStreamOffsets(m_floppyDrive[unit].m_disk); // overwrites m_byte, inits m_bitMask
@ -2116,7 +2116,7 @@ bool Disk2InterfaceCard::LoadSnapshotDriveUnitv3(YamlLoadHelper& yamlLoadHelper,
std::string disk2UnitName = std::string(SS_YAML_KEY_DISK2UNIT) + (unit == DRIVE_1 ? std::string("0") : std::string("1"));
if (!yamlLoadHelper.GetSubMap(disk2UnitName))
throw std::string("Card: Expected key: ") + disk2UnitName;
throw std::runtime_error("Card: Expected key: " + disk2UnitName);
bool bImageError = LoadSnapshotFloppy(yamlLoadHelper, unit, version, track);
@ -2137,10 +2137,10 @@ bool Disk2InterfaceCard::LoadSnapshotDriveUnitv4(YamlLoadHelper& yamlLoadHelper,
std::string disk2UnitName = std::string(SS_YAML_KEY_DISK2UNIT) + (unit == DRIVE_1 ? std::string("0") : std::string("1"));
if (!yamlLoadHelper.GetSubMap(disk2UnitName))
throw std::string("Card: Expected key: ") + disk2UnitName;
throw std::runtime_error("Card: Expected key: " + disk2UnitName);
if (!yamlLoadHelper.GetSubMap(SS_YAML_KEY_FLOPPY))
throw std::string("Card: Expected key: ") + SS_YAML_KEY_FLOPPY;
throw std::runtime_error("Card: Expected key: " SS_YAML_KEY_FLOPPY);
bool bImageError = LoadSnapshotFloppy(yamlLoadHelper, unit, version, track);
@ -2199,7 +2199,7 @@ void Disk2InterfaceCard::LoadSnapshotDriveUnit(YamlLoadHelper& yamlLoadHelper, U
bool Disk2InterfaceCard::LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT version)
{
if (version < 1 || version > kUNIT_VERSION)
throw std::string("Card: wrong version");
throw std::runtime_error("Card: wrong version");
m_currDrive = yamlLoadHelper.LoadUint(SS_YAML_KEY_CURRENT_DRIVE);
m_magnetStates = yamlLoadHelper.LoadUint(SS_YAML_KEY_PHASES);

View File

@ -357,7 +357,7 @@ void FormatTrack::SaveSnapshot(class YamlSaveHelper& yamlSaveHelper)
void FormatTrack::LoadSnapshot(class YamlLoadHelper& yamlLoadHelper)
{
if (!yamlLoadHelper.GetSubMap(SS_YAML_KEY_FORMAT_TRACK))
throw std::string("Card: Expected key: ") + std::string(SS_YAML_KEY_FORMAT_TRACK);
throw std::runtime_error("Card: Expected key: " SS_YAML_KEY_FORMAT_TRACK);
m_bmWrittenSectorAddrFields = yamlLoadHelper.LoadUint(SS_YAML_KEY_WRITTEN_SECTOR_ADDR_FIELDS);
m_WriteTrackStartIndex = yamlLoadHelper.LoadUint(SS_YAML_KEY_WRITE_TRACK_START_IDX);

View File

@ -149,7 +149,7 @@ void FourPlayCard::SaveSnapshot(YamlSaveHelper& yamlSaveHelper)
bool FourPlayCard::LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT version)
{
if (version < 1 || version > kUNIT_VERSION)
throw std::string("Card: wrong version");
throw std::runtime_error("Card: wrong version");
return true;
}

View File

@ -131,7 +131,7 @@ HarddiskInterfaceCard::HarddiskInterfaceCard(UINT slot) :
Card(CT_GenericHDD, slot)
{
if (m_slot != SLOT7) // fixme
throw std::string("Card: wrong slot");
throw std::runtime_error("Card: wrong slot");
m_unitNum = HARDDISK_1 << 7; // b7=unit
@ -823,7 +823,7 @@ bool HarddiskInterfaceCard::LoadSnapshotHDDUnit(YamlLoadHelper& yamlLoadHelper,
{
std::string hddUnitName = std::string(SS_YAML_KEY_HDDUNIT) + (unit == HARDDISK_1 ? std::string("0") : std::string("1"));
if (!yamlLoadHelper.GetSubMap(hddUnitName))
throw std::string("Card: Expected key: ") + hddUnitName;
throw std::runtime_error("Card: Expected key: " + hddUnitName);
m_hardDiskDrive[unit].m_fullname.clear();
m_hardDiskDrive[unit].m_imagename.clear();
@ -843,7 +843,7 @@ bool HarddiskInterfaceCard::LoadSnapshotHDDUnit(YamlLoadHelper& yamlLoadHelper,
m_hardDiskDrive[unit].m_buf_ptr = sizeof(m_hardDiskDrive[unit].m_buf) - 1;
if (!yamlLoadHelper.GetSubMap(SS_YAML_KEY_BUF))
throw hddUnitName + std::string(": Missing: ") + std::string(SS_YAML_KEY_BUF);
throw std::runtime_error(hddUnitName + ": Missing: " + SS_YAML_KEY_BUF);
yamlLoadHelper.LoadMemory(m_hardDiskDrive[unit].m_buf, HD_BLOCK_SIZE);
yamlLoadHelper.PopMap();
@ -888,10 +888,10 @@ bool HarddiskInterfaceCard::LoadSnapshotHDDUnit(YamlLoadHelper& yamlLoadHelper,
bool HarddiskInterfaceCard::LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT version)
{
if (version < 1 || version > kUNIT_VERSION)
throw std::string("Card: wrong version");
throw std::runtime_error("Card: wrong version");
if (version <= 2 && (regs.pc >> 8) == (0xC0|m_slot))
throw std::string("HDD card: 6502 is running old HDD firmware");
throw std::runtime_error("HDD card: 6502 is running old HDD firmware");
m_unitNum = yamlLoadHelper.LoadUint(SS_YAML_KEY_CURRENT_UNIT); // b7=unit
m_command = yamlLoadHelper.LoadUint(SS_YAML_KEY_COMMAND);

View File

@ -48,7 +48,7 @@ LanguageCardUnit::LanguageCardUnit(SS_CARDTYPE type, UINT slot) :
m_uLastRamWrite(0)
{
if (m_slot != LanguageCardUnit::kSlot0)
throw std::string("Language Card: wrong slot"); // throws to the top-level catch-handler, and shuts down
throw std::runtime_error("Language Card: wrong slot"); // throws to the top-level catch-handler, and shuts down
SetMemMainLanguageCard(NULL, true);
}
@ -221,7 +221,7 @@ void LanguageCardSlot0::SaveSnapshot(YamlSaveHelper& yamlSaveHelper)
bool LanguageCardSlot0::LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT version)
{
if (version != kUNIT_LANGUAGECARD_VER)
throw std::string("Card: wrong version");
throw std::runtime_error("Card: wrong version");
// "State"
LoadLCState(yamlLoadHelper);
@ -232,7 +232,7 @@ bool LanguageCardSlot0::LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT versio
}
if (!yamlLoadHelper.GetSubMap(GetSnapshotMemStructName()))
throw std::string("Memory: Missing map name: " + GetSnapshotMemStructName());
throw std::runtime_error("Memory: Missing map name: " + GetSnapshotMemStructName());
yamlLoadHelper.LoadMemory(m_pMemory, kMemBankSize);
@ -419,7 +419,7 @@ void Saturn128K::SaveSnapshot(YamlSaveHelper& yamlSaveHelper)
bool Saturn128K::LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT version)
{
if (version != kUNIT_SATURN_VER)
throw std::string("Card: wrong version");
throw std::runtime_error("Card: wrong version");
// "State"
LoadLCState(yamlLoadHelper);
@ -428,7 +428,7 @@ bool Saturn128K::LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT version)
UINT activeBank = yamlLoadHelper.LoadUint(SS_YAML_KEY_ACTIVE_SATURN_BANK);
if (numBanks < 1 || numBanks > kMaxSaturnBanks || activeBank >= numBanks)
throw std::string(SS_YAML_KEY_UNIT ": Bad Saturn card state");
throw std::runtime_error(SS_YAML_KEY_UNIT ": Bad Saturn card state");
m_uSaturnTotalBanks = numBanks;
m_uSaturnActiveBank = activeBank;
@ -448,7 +448,7 @@ bool Saturn128K::LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT version)
std::string memName = GetSnapshotMemStructName() + szBank;
if (!yamlLoadHelper.GetSubMap(memName))
throw std::string("Memory: Missing map name: " + memName);
throw std::runtime_error("Memory: Missing map name: " + memName);
yamlLoadHelper.LoadMemory(m_aSaturnBanks[uBank], kMemBankSize);

View File

@ -2293,7 +2293,7 @@ bool MemLoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT unitVersion)
//
if (!yamlLoadHelper.GetSubMap( MemGetSnapshotMainMemStructName() ))
throw std::string("Card: Expected key: ") + MemGetSnapshotMainMemStructName();
throw std::runtime_error("Card: Expected key: " + MemGetSnapshotMainMemStructName());
memset(memmain+0xC000, 0, LanguageCardSlot0::kMemBankSize); // Clear it, as high 16K may not be in the save-state's "Main Memory" (eg. the case of II+ Saturn replacing //e LC)
@ -2371,25 +2371,25 @@ static void MemLoadSnapshotAuxCommon(YamlLoadHelper& yamlLoadHelper, const std::
{
type = CT_80Col;
if (numAuxBanks != 0 || activeAuxBank != 0)
throw std::string(SS_YAML_KEY_UNIT ": AuxSlot: Bad aux slot card state");
throw std::runtime_error(SS_YAML_KEY_UNIT ": AuxSlot: Bad aux slot card state");
}
else if (card == SS_YAML_VALUE_CARD_EXTENDED80COL)
{
type = CT_Extended80Col;
if (numAuxBanks != 1 || activeAuxBank != 0)
throw std::string(SS_YAML_KEY_UNIT ": AuxSlot: Bad aux slot card state");
throw std::runtime_error(SS_YAML_KEY_UNIT ": AuxSlot: Bad aux slot card state");
}
else if (card == SS_YAML_VALUE_CARD_RAMWORKSIII)
{
type = CT_RamWorksIII;
if (numAuxBanks < 2 || numAuxBanks > 0x7F || (activeAuxBank+1) > numAuxBanks)
throw std::string(SS_YAML_KEY_UNIT ": AuxSlot: Bad aux slot card state");
throw std::runtime_error(SS_YAML_KEY_UNIT ": AuxSlot: Bad aux slot card state");
}
else
{
// todo: support empty slot
type = CT_Empty;
throw std::string(SS_YAML_KEY_UNIT ": AuxSlot: Unknown card: " + card);
throw std::runtime_error(SS_YAML_KEY_UNIT ": AuxSlot: Unknown card: " + card);
}
g_uMaxExPages = numAuxBanks;
@ -2411,7 +2411,7 @@ static void MemLoadSnapshotAuxCommon(YamlLoadHelper& yamlLoadHelper, const std::
std::string auxMemName = MemGetSnapshotAuxMemStructName() + szBank;
if (!yamlLoadHelper.GetSubMap(auxMemName))
throw std::string("Memory: Missing map name: " + auxMemName);
throw std::runtime_error("Memory: Missing map name: " + auxMemName);
yamlLoadHelper.LoadMemory(pBank, _6502_MEM_LEN);
@ -2436,7 +2436,7 @@ static void MemLoadSnapshotAuxVer2(YamlLoadHelper& yamlLoadHelper)
UINT cardVersion = yamlLoadHelper.LoadUint(SS_YAML_KEY_VERSION);
if (!yamlLoadHelper.GetSubMap(std::string(SS_YAML_KEY_STATE)))
throw std::string(SS_YAML_KEY_UNIT ": Expected sub-map name: " SS_YAML_KEY_STATE);
throw std::runtime_error(SS_YAML_KEY_UNIT ": Expected sub-map name: " SS_YAML_KEY_STATE);
MemLoadSnapshotAuxCommon(yamlLoadHelper, card);
@ -2446,7 +2446,7 @@ static void MemLoadSnapshotAuxVer2(YamlLoadHelper& yamlLoadHelper)
bool MemLoadSnapshotAux(YamlLoadHelper& yamlLoadHelper, UINT unitVersion)
{
if (unitVersion < 1 || unitVersion > kUNIT_AUXSLOT_VER)
throw std::string(SS_YAML_KEY_UNIT ": AuxSlot: Version mismatch");
throw std::runtime_error(SS_YAML_KEY_UNIT ": AuxSlot: Version mismatch");
if (unitVersion == 1)
MemLoadSnapshotAuxVer1(yamlLoadHelper);

View File

@ -1930,7 +1930,7 @@ void MB_SaveSnapshot(YamlSaveHelper& yamlSaveHelper, const UINT uSlot)
static void LoadSnapshotSY6522(YamlLoadHelper& yamlLoadHelper, SY6522& sy6522, UINT version)
{
if (!yamlLoadHelper.GetSubMap(SS_YAML_KEY_SY6522))
throw std::string("Card: Expected key: ") + std::string(SS_YAML_KEY_SY6522);
throw std::runtime_error("Card: Expected key: " SS_YAML_KEY_SY6522);
sy6522.ORB = yamlLoadHelper.LoadUint(SS_YAML_KEY_SY6522_REG_ORB);
sy6522.ORA = yamlLoadHelper.LoadUint(SS_YAML_KEY_SY6522_REG_ORA);
@ -1968,10 +1968,10 @@ static void LoadSnapshotSY6522(YamlLoadHelper& yamlLoadHelper, SY6522& sy6522, U
bool MB_LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT slot, UINT version)
{
if (slot != 4 && slot != 5) // fixme
throw std::string("Card: wrong slot");
throw std::runtime_error("Card: wrong slot");
if (version < 1 || version > kUNIT_VERSION)
throw std::string("Card: wrong version");
throw std::runtime_error("Card: wrong version");
AY8910UpdateSetCycles();
@ -1987,7 +1987,7 @@ bool MB_LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT slot, UINT version)
char szNum[2] = {char('0' + i), 0};
std::string unit = std::string(SS_YAML_KEY_MB_UNIT) + std::string(szNum);
if (!yamlLoadHelper.GetSubMap(unit))
throw std::string("Card: Expected key: ") + std::string(unit);
throw std::runtime_error("Card: Expected key: " + unit);
LoadSnapshotSY6522(yamlLoadHelper, pMB->sy6522, version);
UpdateIFR(pMB, 0, pMB->sy6522.IFR); // Assert any pending IRQs (GH#677)
@ -2053,7 +2053,7 @@ bool MB_LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT slot, UINT version)
void Phasor_SaveSnapshot(YamlSaveHelper& yamlSaveHelper, const UINT uSlot)
{
if (uSlot != 4)
throw std::string("Card: Phasor only supported in slot-4");
throw std::runtime_error("Card: Phasor only supported in slot-4");
UINT nDeviceNum = 0;
SY6522_AY8910* pMB = &g_MB[0]; // fixme: Phasor uses MB's slot4(2x6522), slot4(2xSSI263), but slot4+5(4xAY8910)
@ -2091,10 +2091,10 @@ void Phasor_SaveSnapshot(YamlSaveHelper& yamlSaveHelper, const UINT uSlot)
bool Phasor_LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT slot, UINT version)
{
if (slot != 4) // fixme
throw std::string("Card: wrong slot");
throw std::runtime_error("Card: wrong slot");
if (version < 1 || version > kUNIT_VERSION)
throw std::string("Card: wrong version");
throw std::runtime_error("Card: wrong version");
if (version < 6)
yamlLoadHelper.LoadUint(SS_YAML_KEY_PHASOR_CLOCK_SCALE_FACTOR); // Consume redundant data
@ -2123,7 +2123,7 @@ bool Phasor_LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT slot, UINT version
char szNum[2] = {char('0' + i), 0};
std::string unit = std::string(SS_YAML_KEY_MB_UNIT) + std::string(szNum);
if (!yamlLoadHelper.GetSubMap(unit))
throw std::string("Card: Expected key: ") + std::string(unit);
throw std::runtime_error("Card: Expected key: " + unit);
LoadSnapshotSY6522(yamlLoadHelper, pMB->sy6522, version);
UpdateIFR(pMB, 0, pMB->sy6522.IFR); // Assert any pending IRQs (GH#677)

View File

@ -139,7 +139,7 @@ CMouseInterface::CMouseInterface(UINT slot) :
m_syncEvent(slot, 0, SyncEventCallback) // use slot# as "unique" id for MouseInterfaces
{
if (m_slot != 4) // fixme
throw std::string("Card: wrong slot");
throw std::runtime_error("Card: wrong slot");
m_6821.SetListenerB( this, M6821_Listener_B );
m_6821.SetListenerA( this, M6821_Listener_A );
@ -695,7 +695,7 @@ void CMouseInterface::SaveSnapshot(YamlSaveHelper& yamlSaveHelper)
void CMouseInterface::LoadSnapshotMC6821(YamlLoadHelper& yamlLoadHelper, std::string key)
{
if (!yamlLoadHelper.GetSubMap(key))
throw std::string("Card: Expected key: ") + key;
throw std::runtime_error("Card: Expected key: " + key);
mc6821_t mc6821;
mc6821.pra = yamlLoadHelper.LoadUint(SS_YAML_KEY_PRA);
@ -716,7 +716,7 @@ void CMouseInterface::LoadSnapshotMC6821(YamlLoadHelper& yamlLoadHelper, std::st
bool CMouseInterface::LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT version)
{
if (version != 1)
throw std::string("Card: wrong version");
throw std::runtime_error("Card: wrong version");
LoadSnapshotMC6821(yamlLoadHelper, SS_YAML_KEY_MC6821);
@ -726,7 +726,7 @@ bool CMouseInterface::LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT version)
m_by6821A = yamlLoadHelper.LoadUint(SS_YAML_KEY_6821A);
if (!yamlLoadHelper.GetSubMap(SS_YAML_KEY_BUFF))
throw std::string("Card: Expected key: " SS_YAML_KEY_BUFF);
throw std::runtime_error("Card: Expected key: " SS_YAML_KEY_BUFF);
yamlLoadHelper.LoadMemory(m_byBuff, sizeof(m_byBuff));
yamlLoadHelper.PopMap();

View File

@ -230,10 +230,10 @@ void Printer_SaveSnapshot(class YamlSaveHelper& yamlSaveHelper, const UINT uSlot
bool Printer_LoadSnapshot(class YamlLoadHelper& yamlLoadHelper, UINT slot, UINT version)
{
if (slot != 1) // fixme
throw std::string("Card: wrong slot");
throw std::runtime_error("Card: wrong slot");
if (version != 1)
throw std::string("Card: wrong version");
throw std::runtime_error("Card: wrong version");
inactivity = yamlLoadHelper.LoadUint(SS_YAML_KEY_INACTIVITY);
g_PrinterIdleLimit = yamlLoadHelper.LoadUint(SS_YAML_KEY_IDLELIMIT);
@ -245,7 +245,7 @@ bool Printer_LoadSnapshot(class YamlLoadHelper& yamlLoadHelper, UINT slot, UINT
g_bPrinterAppend = true; // Re-open print-file in append mode
BOOL bRes = CheckPrint();
if (!bRes)
throw std::string("Printer Card: Unable to resume printing to file");
throw std::runtime_error("Printer Card: Unable to resume printing to file");
}
else
{

View File

@ -1311,7 +1311,7 @@ void RGB_SaveSnapshot(YamlSaveHelper& yamlSaveHelper)
void RGB_LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT cardVersion)
{
if (!yamlLoadHelper.GetSubMap(SS_YAML_KEY_RGB_CARD))
throw std::string("Card: Expected key: ") + std::string(SS_YAML_KEY_RGB_CARD);
throw std::runtime_error("Card: Expected key: " SS_YAML_KEY_RGB_CARD);
g_rgbFlags = yamlLoadHelper.LoadUint(SS_YAML_KEY_RGB_FLAGS);
g_rgbMode = yamlLoadHelper.LoadUint(SS_YAML_KEY_RGB_MODE);

View File

@ -113,7 +113,7 @@ void SAMCard::SaveSnapshot(YamlSaveHelper& yamlSaveHelper)
bool SAMCard::LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT version)
{
if (version < 1 || version > kUNIT_VERSION)
throw std::string("Card: wrong version");
throw std::runtime_error("Card: wrong version");
return true;
}

View File

@ -230,7 +230,7 @@ void SNESMAXCard::SaveSnapshot(YamlSaveHelper& yamlSaveHelper)
bool SNESMAXCard::LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT version)
{
if (version < 1 || version > kUNIT_VERSION)
throw std::string("Card: wrong version");
throw std::runtime_error("Card: wrong version");
m_buttonIndex = yamlLoadHelper.LoadUint(SS_YAML_KEY_BUTTON_INDEX);

View File

@ -868,7 +868,7 @@ void SSI263::SaveSnapshot(YamlSaveHelper& yamlSaveHelper)
void SSI263::LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT device, PHASOR_MODE mode, UINT version)
{
if (!yamlLoadHelper.GetSubMap(SS_YAML_KEY_SSI263))
throw std::string("Card: Expected key: ") + std::string(SS_YAML_KEY_SSI263);
throw std::runtime_error("Card: Expected key: " SS_YAML_KEY_SSI263);
m_durationPhoneme = yamlLoadHelper.LoadUint(SS_YAML_KEY_SSI263_REG_DUR_PHON);
m_inflection = yamlLoadHelper.LoadUint(SS_YAML_KEY_SSI263_REG_INF);

View File

@ -222,7 +222,7 @@ static eApple2Type ParseApple2Type(std::string type)
else if (type == SS_YAML_VALUE_TK30002E) return A2TYPE_TK30002E;
else if (type == SS_YAML_VALUE_BASE64A) return A2TYPE_BASE64A;
throw std::string("Load: Unknown Apple2 type");
throw std::runtime_error("Load: Unknown Apple2 type");
}
static std::string GetApple2TypeAsString(void)
@ -241,7 +241,7 @@ static std::string GetApple2TypeAsString(void)
case A2TYPE_TK30002E: return SS_YAML_VALUE_TK30002E;
case A2TYPE_BASE64A: return SS_YAML_VALUE_BASE64A;
default:
throw std::string("Save: Unknown Apple2 type");
throw std::runtime_error("Save: Unknown Apple2 type");
}
}
@ -251,10 +251,10 @@ static UINT ParseFileHdr(void)
{
std::string scalar;
if (!yamlHelper.GetScalar(scalar))
throw std::string(SS_YAML_KEY_FILEHDR ": Failed to find scalar");
throw std::runtime_error(SS_YAML_KEY_FILEHDR ": Failed to find scalar");
if (scalar != SS_YAML_KEY_FILEHDR)
throw std::string("Failed to find file header");
throw std::runtime_error("Failed to find file header");
yamlHelper.GetMapStartEvent();
@ -266,7 +266,7 @@ static UINT ParseFileHdr(void)
if (value != SS_YAML_VALUE_AWSS)
{
//printf("%s: Bad tag (%s) - expected %s\n", SS_YAML_KEY_FILEHDR, value.c_str(), SS_YAML_VALUE_AWSS);
throw std::string(SS_YAML_KEY_FILEHDR ": Bad tag");
throw std::runtime_error(SS_YAML_KEY_FILEHDR ": Bad tag");
}
return yamlLoadHelper.LoadUint(SS_YAML_KEY_VERSION);
@ -277,7 +277,7 @@ static UINT ParseFileHdr(void)
static void ParseUnitApple2(YamlLoadHelper& yamlLoadHelper, UINT version)
{
if (version == 0 || version > UNIT_APPLE2_VER)
throw std::string(SS_YAML_KEY_UNIT ": Apple2: Version mismatch");
throw std::runtime_error(SS_YAML_KEY_UNIT ": Apple2: Version mismatch");
std::string model = yamlLoadHelper.LoadString(SS_YAML_KEY_MODEL);
SetApple2Type( ParseApple2Type(model) ); // NB. Sets default main CPU type
@ -296,7 +296,7 @@ static void ParseUnitApple2(YamlLoadHelper& yamlLoadHelper, UINT version)
static void ParseSlots(YamlLoadHelper& yamlLoadHelper, UINT unitVersion)
{
if (unitVersion != UNIT_SLOTS_VER)
throw std::string(SS_YAML_KEY_UNIT ": Slots: Version mismatch");
throw std::runtime_error(SS_YAML_KEY_UNIT ": Slots: Version mismatch");
while (1)
{
@ -307,7 +307,7 @@ static void ParseSlots(YamlLoadHelper& yamlLoadHelper, UINT unitVersion)
const int slot = strtoul(scalar.c_str(), NULL, 10); // NB. aux slot supported as a different "unit"
// NB. slot-0 only supported for Apple II or II+ (or similar clones)
if (slot < SLOT0 || slot > SLOT7)
throw std::string("Slots: Invalid slot #: ") + scalar;
throw std::runtime_error("Slots: Invalid slot #: " + scalar);
yamlLoadHelper.GetSubMap(scalar);
@ -315,7 +315,7 @@ static void ParseSlots(YamlLoadHelper& yamlLoadHelper, UINT unitVersion)
UINT cardVersion = yamlLoadHelper.LoadUint(SS_YAML_KEY_VERSION);
if (!yamlLoadHelper.GetSubMap(std::string(SS_YAML_KEY_STATE), true)) // NB. For some cards, State can be null
throw std::string(SS_YAML_KEY_UNIT ": Expected sub-map name: " SS_YAML_KEY_STATE);
throw std::runtime_error(SS_YAML_KEY_UNIT ": Expected sub-map name: " SS_YAML_KEY_STATE);
SS_CARDTYPE type = CT_Empty;
bool bRes = false;
@ -382,7 +382,7 @@ static void ParseSlots(YamlLoadHelper& yamlLoadHelper, UINT unitVersion)
}
else
{
throw std::string("Slots: Unknown card: " + card); // todo: don't throw - just ignore & continue
throw std::runtime_error("Slots: Unknown card: " + card); // todo: don't throw - just ignore & continue
}
if (slot == 0)
@ -414,7 +414,7 @@ static void ParseUnit(void)
UINT unitVersion = yamlLoadHelper.LoadUint(SS_YAML_KEY_VERSION);
if (!yamlLoadHelper.GetSubMap(std::string(SS_YAML_KEY_STATE)))
throw std::string(SS_YAML_KEY_UNIT ": Expected sub-map name: " SS_YAML_KEY_STATE);
throw std::runtime_error(SS_YAML_KEY_UNIT ": Expected sub-map name: " SS_YAML_KEY_STATE);
if (unit == GetSnapshotUnitApple2Name())
{
@ -438,7 +438,7 @@ static void ParseUnit(void)
}
else
{
throw std::string(SS_YAML_KEY_UNIT ": Unknown type: " ) + unit;
throw std::runtime_error(SS_YAML_KEY_UNIT ": Unknown type: " + unit);
}
}
@ -452,10 +452,10 @@ static void Snapshot_LoadState_v2(void)
try
{
if (!yamlHelper.InitParser( g_strSaveStatePathname.c_str() ))
throw std::string("Failed to initialize parser or open file");
throw std::runtime_error("Failed to initialize parser or open file");
if (ParseFileHdr() != SS_FILE_VER)
throw std::string("Version mismatch");
throw std::runtime_error("Version mismatch");
//
@ -485,7 +485,7 @@ static void Snapshot_LoadState_v2(void)
if (scalar == SS_YAML_KEY_UNIT)
ParseUnit();
else
throw std::string("Unknown top-level scalar: " + scalar);
throw std::runtime_error("Unknown top-level scalar: " + scalar);
}
MB_SetCumulativeCycles();
@ -517,10 +517,10 @@ static void Snapshot_LoadState_v2(void)
// g_Apple2Type may've changed: so reload button bitmaps & redraw frame (title, buttons, leds, etc)
frame.FrameUpdateApple2Type(); // NB. Calls VideoRedrawScreen()
}
catch(std::string szMessage)
catch(const std::exception & szMessage)
{
frame.FrameMessageBox(
szMessage.c_str(),
szMessage.what(),
TEXT("Load State"),
MB_ICONEXCLAMATION | MB_SETFOREGROUND);
@ -593,10 +593,10 @@ void Snapshot_SaveState(void)
NoSlotClockSaveSnapshot(yamlSaveHelper);
}
}
catch(std::string szMessage)
catch(const std::exception & szMessage)
{
GetFrame().FrameMessageBox(
szMessage.c_str(),
szMessage.what(),
TEXT("Save State"),
MB_ICONEXCLAMATION | MB_SETFOREGROUND);
}

View File

@ -72,7 +72,7 @@ CSuperSerialCard::CSuperSerialCard(UINT slot) :
m_pExpansionRom(NULL)
{
if (m_slot != 2) // fixme
throw std::string("Card: wrong slot");
throw std::runtime_error("Card: wrong slot");
m_dwSerialPortItem = 0;
@ -1466,7 +1466,7 @@ void CSuperSerialCard::SaveSnapshot(YamlSaveHelper& yamlSaveHelper)
void CSuperSerialCard::LoadSnapshotDIPSW(YamlLoadHelper& yamlLoadHelper, std::string key, SSC_DIPSW& dipsw)
{
if (!yamlLoadHelper.GetSubMap(key))
throw std::string("Card: Expected key: " + key);
throw std::runtime_error("Card: Expected key: " + key);
dipsw.uBaudRate = yamlLoadHelper.LoadUint(SS_YAML_KEY_BAUDRATE);
dipsw.eFirmwareMode = (eFWMODE) yamlLoadHelper.LoadUint(SS_YAML_KEY_FWMODE);
@ -1482,7 +1482,7 @@ void CSuperSerialCard::LoadSnapshotDIPSW(YamlLoadHelper& yamlLoadHelper, std::st
bool CSuperSerialCard::LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT version)
{
if (version < 1 || version > kUNIT_VERSION)
throw std::string("Card: wrong version");
throw std::runtime_error("Card: wrong version");
LoadSnapshotDIPSW(yamlLoadHelper, SS_YAML_KEY_DIPSWDEFAULT, m_DIPSWDefault);
LoadSnapshotDIPSW(yamlLoadHelper, SS_YAML_KEY_DIPSWCURRENT, m_DIPSWCurrent);

View File

@ -1507,10 +1507,10 @@ void tfe_SaveSnapshot(class YamlSaveHelper& yamlSaveHelper, const UINT uSlot)
bool tfe_LoadSnapshot(class YamlLoadHelper& yamlLoadHelper, UINT slot, UINT version)
{
if (slot != SLOT3) // fixme
throw std::string("Card: wrong slot");
throw std::runtime_error("Card: wrong slot");
if (version < 1 || version > kUNIT_VERSION)
throw std::string("Card: wrong version");
throw std::runtime_error("Card: wrong version");
tfe_enabled = yamlLoadHelper.LoadBool(SS_YAML_KEY_ENABLED) ? true : false;
set_tfe_interface(yamlLoadHelper.LoadString(SS_YAML_KEY_NETWORK_INTERFACE));
@ -1522,14 +1522,14 @@ bool tfe_LoadSnapshot(class YamlLoadHelper& yamlLoadHelper, UINT slot, UINT vers
rx_buffer = yamlLoadHelper.LoadUint(SS_YAML_KEY_RX_BUFFER);
if (!yamlLoadHelper.GetSubMap(SS_YAML_KEY_CS8900A_REGS))
throw std::string("Card: Expected key: ") + SS_YAML_KEY_CS8900A_REGS;
throw std::runtime_error("Card: Expected key: " SS_YAML_KEY_CS8900A_REGS);
memset(tfe, 0, TFE_COUNT_IO_REGISTER);
yamlLoadHelper.LoadMemory(tfe, TFE_COUNT_IO_REGISTER);
yamlLoadHelper.PopMap();
if (!yamlLoadHelper.GetSubMap(SS_YAML_KEY_PACKETPAGE_REGS))
throw std::string("Card: Expected key: ") + SS_YAML_KEY_PACKETPAGE_REGS;
throw std::runtime_error("Card: Expected key: " SS_YAML_KEY_PACKETPAGE_REGS);
memset(tfe_packetpage, 0, MAX_PACKETPAGE_ARRAY);
yamlLoadHelper.LoadMemory(tfe_packetpage, MAX_PACKETPAGE_ARRAY);

View File

@ -179,7 +179,7 @@ void VidHDCard::SaveSnapshot(YamlSaveHelper& yamlSaveHelper)
bool VidHDCard::LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT version)
{
if (version < 1 || version > kUNIT_VERSION)
throw std::string("Card: wrong version");
throw std::runtime_error("Card: wrong version");
m_SCREENCOLOR = yamlLoadHelper.LoadUint(SS_YAML_KEY_SCREEN_COLOR);
m_NEWVIDEO = yamlLoadHelper.LoadUint(SS_YAML_KEY_NEW_VIDEO);

View File

@ -569,18 +569,10 @@ int APIENTRY WinMain(HINSTANCE passinstance, HINSTANCE, LPSTR lpCmdLine, int)
}
while (g_bRestart);
}
catch(std::runtime_error exception)
catch(const std::exception & exception)
{
ExceptionHandler(exception.what());
}
catch(std::exception exception)
{
ExceptionHandler(exception.what());
}
catch(std::string error)
{
ExceptionHandler(error.c_str());
}
Shutdown();
return 0;

View File

@ -26,6 +26,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "YamlHelper.h"
#include "Log.h"
#include <sstream>
int YamlHelper::InitParser(const char* pPathname)
{
m_hFile = fopen(pPathname, "r");
@ -61,10 +63,14 @@ void YamlHelper::GetNextEvent(void)
yaml_event_delete(&m_newEvent);
if (!yaml_parser_parse(&m_parser, &m_newEvent))
{
std::string error = std::string("Save-state parser error: ");
if (m_parser.problem != NULL) error += std::string(m_parser.problem);
else error += std::string("unknown");
throw error;
std::ostringstream error("Save-state parser error: ");
if (m_parser.problem != NULL)
error << m_parser.problem;
else
error << "unknown";
error << " @ " << m_parser.problem_mark.line << ":" << m_parser.problem_mark.column;
throw std::runtime_error(error.str());
}
}
@ -109,7 +115,7 @@ void YamlHelper::GetMapStartEvent(void)
if (m_newEvent.type != YAML_MAPPING_START_EVENT)
{
//printf("Unexpected yaml event (%d)\n", m_newEvent.type);
throw std::string("Unexpected yaml event");
throw std::runtime_error("Unexpected yaml event");
}
}
@ -142,7 +148,7 @@ int YamlHelper::ParseMap(MapYaml& mapYaml)
mapYaml[pKey] = mapValue;
res = ParseMap(*mapValue.subMap);
if (!res)
throw std::string("ParseMap: premature end of file during map parsing");
throw std::runtime_error("ParseMap: premature end of file during map parsing");
bKey = true; // possibly more key,value pairs in this map
}
break;
@ -168,7 +174,7 @@ int YamlHelper::ParseMap(MapYaml& mapYaml)
break;
case YAML_SEQUENCE_START_EVENT:
case YAML_SEQUENCE_END_EVENT:
throw std::string("ParseMap: Sequence event unsupported");
throw std::runtime_error("ParseMap: Sequence event unsupported");
}
}
@ -250,28 +256,28 @@ UINT YamlHelper::LoadMemory(MapYaml& mapYaml, const LPBYTE pMemBase, const size_
const char* pKey = it->first.c_str();
UINT addr = strtoul(pKey, NULL, 16);
if (addr >= kAddrSpaceSize)
throw std::string("Memory: line address too big: " + it->first);
throw std::runtime_error("Memory: line address too big: " + it->first);
LPBYTE pDst = (LPBYTE) (pMemBase + addr);
const LPBYTE pDstEnd = (LPBYTE) (pMemBase + kAddrSpaceSize);
if (it->second.subMap)
throw std::string("Memory: unexpected sub-map");
throw std::runtime_error("Memory: unexpected sub-map");
const char* pValue = it->second.value.c_str();
size_t len = strlen(pValue);
if (len & 1)
throw std::string("Memory: hex data must be an even number of nibbles on line address: " + it->first);
throw std::runtime_error("Memory: hex data must be an even number of nibbles on line address: " + it->first);
for (UINT i = 0; i<len; i+=2)
{
if (pDst >= pDstEnd)
throw std::string("Memory: hex data overflowed address space on line address: " + it->first);
throw std::runtime_error("Memory: hex data overflowed address space on line address: " + it->first);
BYTE ah = m_AsciiToHex[ (BYTE)(*pValue++) ];
BYTE al = m_AsciiToHex[ (BYTE)(*pValue++) ];
if ((ah | al) & 0x80)
throw std::string("Memory: hex data contains illegal character on line address: " + it->first);
throw std::runtime_error("Memory: hex data contains illegal character on line address: " + it->first);
*pDst++ = (ah<<4) | al;
bytes++;
@ -292,7 +298,7 @@ INT YamlLoadHelper::LoadInt(const std::string key)
if (value == "")
{
m_bDoGetMapRemainder = false;
throw std::string(m_currentMapName + ": Missing: " + key);
throw std::runtime_error(m_currentMapName + ": Missing: " + key);
}
return strtol(value.c_str(), NULL, 0);
}
@ -304,7 +310,7 @@ UINT YamlLoadHelper::LoadUint(const std::string key)
if (value == "")
{
m_bDoGetMapRemainder = false;
throw std::string(m_currentMapName + ": Missing: " + key);
throw std::runtime_error(m_currentMapName + ": Missing: " + key);
}
return strtoul(value.c_str(), NULL, 0);
}
@ -316,7 +322,7 @@ UINT64 YamlLoadHelper::LoadUint64(const std::string key)
if (value == "")
{
m_bDoGetMapRemainder = false;
throw std::string(m_currentMapName + ": Missing: " + key);
throw std::runtime_error(m_currentMapName + ": Missing: " + key);
}
return _strtoui64(value.c_str(), NULL, 0);
}
@ -330,7 +336,7 @@ bool YamlLoadHelper::LoadBool(const std::string key)
else if (value == "false")
return false;
m_bDoGetMapRemainder = false;
throw std::string(m_currentMapName + ": Missing: " + key);
throw std::runtime_error(m_currentMapName + ": Missing: " + key);
}
std::string YamlLoadHelper::LoadString_NoThrow(const std::string& key, bool& bFound)
@ -346,7 +352,7 @@ std::string YamlLoadHelper::LoadString(const std::string& key)
if (!bFound)
{
m_bDoGetMapRemainder = false;
throw std::string(m_currentMapName + ": Missing: " + key);
throw std::runtime_error(m_currentMapName + ": Missing: " + key);
}
return value;
}
@ -358,7 +364,7 @@ float YamlLoadHelper::LoadFloat(const std::string& key)
if (value == "")
{
m_bDoGetMapRemainder = false;
throw std::string(m_currentMapName + ": Missing: " + key);
throw std::runtime_error(m_currentMapName + ": Missing: " + key);
}
#if (_MSC_VER >= 1900)
return strtof(value.c_str(), NULL); // MSVC++ 14.0 _MSC_VER == 1900 (Visual Studio 2015 version 14.0)
@ -374,7 +380,7 @@ double YamlLoadHelper::LoadDouble(const std::string& key)
if (value == "")
{
m_bDoGetMapRemainder = false;
throw std::string(m_currentMapName + ": Missing: " + key);
throw std::runtime_error(m_currentMapName + ": Missing: " + key);
}
return strtod(value.c_str(), NULL);
}
@ -465,7 +471,7 @@ void YamlSaveHelper::SaveString(const char* key, const char* value)
{
int size = MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, value, -1, NULL, 0);
if (size == 0)
throw std::string("Unable to convert to unicode: ") + std::string(value);
throw std::runtime_error("Unable to convert to unicode: " + std::string(value));
if (size > m_wcStrSize)
{
delete[] m_pWcStr;
@ -474,7 +480,7 @@ void YamlSaveHelper::SaveString(const char* key, const char* value)
}
int res = MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, value, -1, m_pWcStr, m_wcStrSize);
if (!res)
throw std::string("Unable to convert to unicode: ") + std::string(value);
throw std::runtime_error("Unable to convert to unicode: " + std::string(value));
}
// 2) unicode -> UTF-8
@ -482,7 +488,7 @@ void YamlSaveHelper::SaveString(const char* key, const char* value)
// NB. WC_ERR_INVALID_CHARS only defined when WIN_VER >= 0x600 - but stdafx.h defines it as 0x500
int size = WideCharToMultiByte(CP_UTF8, 0/*WC_ERR_INVALID_CHARS*/, m_pWcStr, -1, NULL, 0, NULL, NULL);
if (size == 0)
throw std::string("Unable to convert to UTF-8: ") + std::string(value);
throw std::runtime_error("Unable to convert to UTF-8: " + std::string(value));
if (size > m_mbStrSize)
{
delete[] m_pMbStr;
@ -491,7 +497,7 @@ void YamlSaveHelper::SaveString(const char* key, const char* value)
}
int res = WideCharToMultiByte(CP_UTF8, 0/*WC_ERR_INVALID_CHARS*/, m_pWcStr, -1, m_pMbStr, m_mbStrSize, NULL, NULL);
if (!res)
throw std::string("Unable to convert to UTF-8: ") + std::string(value);
throw std::runtime_error("Unable to convert to UTF-8: " + std::string(value));
}
Save("%s: %s\n", key, m_pMbStr);
@ -516,7 +522,7 @@ void YamlSaveHelper::SaveDouble(const char* key, double value)
void YamlSaveHelper::SaveMemory(const LPBYTE pMemBase, const UINT uMemSize)
{
if (uMemSize & 7)
throw std::string("Memory: size must be multiple of 8");
throw std::runtime_error("Memory: size must be multiple of 8");
const UINT kIndent = m_indent;

View File

@ -82,7 +82,7 @@ public:
if (!m_yamlHelper.ParseMap(yamlHelper.m_mapYaml))
{
m_bDoGetMapRemainder = false;
throw std::string(m_currentMapName + ": Failed to parse map");
throw std::runtime_error(m_currentMapName + ": Failed to parse map");
}
}
@ -184,7 +184,7 @@ public:
// - at this point any old file will have been truncated to zero
if(m_hFile == NULL)
throw std::string("Save error");
throw std::runtime_error("Save error");
_tzset();
time_t ltime;

View File

@ -6525,10 +6525,10 @@ void Z80_SaveSnapshot(class YamlSaveHelper& yamlSaveHelper, const UINT uSlot)
bool Z80_LoadSnapshot(class YamlLoadHelper& yamlLoadHelper, UINT uSlot, UINT version)
{
if (uSlot != 4 && uSlot != 5) // fixme
throw std::string("Card: wrong slot");
throw std::runtime_error("Card: wrong slot");
if (version != 1)
throw std::string("Card: wrong version");
throw std::runtime_error("Card: wrong version");
reg_a = yamlLoadHelper.LoadUint(SS_YAML_KEY_REGA);
reg_b = yamlLoadHelper.LoadUint(SS_YAML_KEY_REGB);