aboutsummaryrefslogtreecommitdiff
path: root/src/db.cpp
diff options
context:
space:
mode:
authorGavin Andresen <gavinandresen@gmail.com>2012-10-08 15:18:04 -0400
committerGavin Andresen <gavinandresen@gmail.com>2012-10-08 17:25:17 -0400
commit8d5f461cb6d4bb954fef5c3deebe2b2a7bdbfe27 (patch)
treea41c410e8fe04edd5e01d714979b1ef09b44cd42 /src/db.cpp
parent43de64949c96b6d708b7d8a82c3dba0f6ddf059e (diff)
downloadbitcoin-8d5f461cb6d4bb954fef5c3deebe2b2a7bdbfe27.tar.xz
Handle incompatible BDB environments
Before, opening a -datadir that was created with a new version of Berkeley DB would result in an un-caught DB_RUNRECOVERY exception. After these changes, the error is caught and the user is told that there is a problem and is told how to try to recover from it.
Diffstat (limited to 'src/db.cpp')
-rw-r--r--src/db.cpp19
1 files changed, 7 insertions, 12 deletions
diff --git a/src/db.cpp b/src/db.cpp
index 867703fbd2..7ca9e34953 100644
--- a/src/db.cpp
+++ b/src/db.cpp
@@ -34,19 +34,14 @@ void CDBEnv::EnvShutdown()
return;
fDbEnvInit = false;
- try
- {
- dbenv.close(0);
- }
- catch (const DbException& e)
- {
- printf("EnvShutdown exception: %s (%d)\n", e.what(), e.get_errno());
- }
+ int ret = dbenv.close(0);
+ if (ret != 0)
+ printf("EnvShutdown exception: %s (%d)\n", DbEnv::strerror(ret), ret);
if (!fMockDb)
DbEnv(0).remove(GetDataDir().string().c_str(), 0);
}
-CDBEnv::CDBEnv() : dbenv(0)
+CDBEnv::CDBEnv() : dbenv(DB_CXX_NO_EXCEPTIONS)
{
}
@@ -100,8 +95,8 @@ bool CDBEnv::Open(boost::filesystem::path pathEnv_)
DB_RECOVER |
nEnvFlags,
S_IRUSR | S_IWUSR);
- if (ret > 0)
- return error("CDB() : error %d opening database environment", ret);
+ if (ret != 0)
+ return error("CDB() : error %s (%d) opening database environment", DbEnv::strerror(ret), ret);
fDbEnvInit = true;
fMockDb = false;
@@ -191,7 +186,7 @@ CDB::CDB(const char *pszFile, const char* pszMode) :
nFlags, // Flags
0);
- if (ret > 0)
+ if (ret != 0)
{
delete pdb;
pdb = NULL;