Show error message if ReadConfigFile fails

A runaway exception was raised if ReadConfigFile fails (usually
due to a parse error in bitcoin.conf). Show an error message instead.

Fixes #4013.
This commit is contained in:
Wladimir J. van der Laan 2014-04-07 10:10:01 +02:00 committed by langerhans
parent b560c9bd6d
commit c5b35deae6
3 changed files with 20 additions and 3 deletions

View file

@ -27,7 +27,12 @@ static bool AppInitRPC(int argc, char* argv[])
fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", mapArgs["-datadir"].c_str());
return false;
}
ReadConfigFile(mapArgs, mapMultiArgs);
try {
ReadConfigFile(mapArgs, mapMultiArgs);
} catch(std::exception &e) {
fprintf(stderr,"Error reading configuration file: %s\n", e.what());
return false;
}
// Check for -testnet or -regtest parameter (TestNet() calls are only valid after this clause)
if (!SelectParamsFromCommandLine()) {
fprintf(stderr, "Error: Invalid combination of -regtest and -testnet.\n");

View file

@ -70,7 +70,13 @@ bool AppInit(int argc, char* argv[])
fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", mapArgs["-datadir"].c_str());
return false;
}
ReadConfigFile(mapArgs, mapMultiArgs);
try
{
ReadConfigFile(mapArgs, mapMultiArgs);
} catch(std::exception &e) {
fprintf(stderr,"Error reading configuration file: %s\n", e.what());
return false;
}
// Check for -testnet or -regtest parameter (TestNet() calls are only valid after this clause)
if (!SelectParamsFromCommandLine()) {
fprintf(stderr, "Error: Invalid combination of -regtest and -testnet.\n");

View file

@ -521,7 +521,13 @@ int main(int argc, char *argv[])
QObject::tr("Error: Specified data directory \"%1\" does not exist.").arg(QString::fromStdString(mapArgs["-datadir"])));
return 1;
}
ReadConfigFile(mapArgs, mapMultiArgs);
try {
ReadConfigFile(mapArgs, mapMultiArgs);
} catch(std::exception &e) {
QMessageBox::critical(0, QObject::tr("Bitcoin"),
QObject::tr("Error: Cannot parse configuration file: %1. Only use key=value syntax.").arg(e.what()));
return false;
}
/// 7. Determine network (and switch to network specific options)
// - Do not call Params() before this step