summaryrefslogtreecommitdiff
path: root/examples/cxx/EnvExample.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/cxx/EnvExample.cpp')
-rw-r--r--examples/cxx/EnvExample.cpp33
1 files changed, 28 insertions, 5 deletions
diff --git a/examples/cxx/EnvExample.cpp b/examples/cxx/EnvExample.cpp
index 4cece0af..bf8a9dd7 100644
--- a/examples/cxx/EnvExample.cpp
+++ b/examples/cxx/EnvExample.cpp
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1997, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015 Oracle and/or its affiliates. All rights reserved.
*
* $Id$
*/
@@ -82,6 +82,8 @@ main(int argc, char *argv[])
void
db_setup(const char *home, const char *data_dir, ostream& err_stream)
{
+ const char * err1 = "DbEnv::open: No such file or directory";
+ const char * err2 = "Db::open: No such file or directory";
//
// Create an environment object and initialize it for error
// reporting.
@@ -100,9 +102,19 @@ db_setup(const char *home, const char *data_dir, ostream& err_stream)
(void)dbenv->set_data_dir(data_dir);
// Open the environment with full transactional support.
- dbenv->open(home,
- DB_CREATE | DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_MPOOL |
- DB_INIT_TXN, 0);
+ try {
+ dbenv->open(home,
+ DB_CREATE | DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_MPOOL |
+ DB_INIT_TXN, 0);
+ }
+ catch (DbException &dbe) {
+ cerr << "EnvExample: " << dbe.what() << "\n";
+ if (!strcmp(dbe.what(), err1)){
+ cout << "Please check whether "
+ << "home dir \"" << home << "\" exists.\n";
+ }
+ exit (-1);
+ }
// Open a database in the environment to verify the data_dir
// has been set correctly.
@@ -110,7 +122,18 @@ db_setup(const char *home, const char *data_dir, ostream& err_stream)
Db *db = new Db(dbenv, 0) ;
// Open the database.
- db->open(NULL, "EvnExample_db1.db", NULL, DB_BTREE, DB_CREATE, 0644);
+ try {
+ db->open(NULL, "EvnExample_db1.db",
+ NULL, DB_BTREE, DB_CREATE, 0644);
+ }
+ catch (DbException &dbe) {
+ cerr << "EnvExample: " << dbe.what() << "\n";
+ if (!strcmp(dbe.what(), err2)){
+ cout << "Please check whether data dir \"" << data_dir
+ << "\" exists under \"" << home << "\"\n";
+ }
+ exit (-1);
+ }
// Close the database handle.
db->close(0) ;