static member initialization in a try/catch block?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



All,

I am trying to design a cache object (singleton) that gets the desired object directly from the database if it is not already in the cache.

The db connection is a static class member:

Cache.h:
class Cache {
    static log4cxx::LoggerPtr logger;
    static pqxx::connection dbCon;
public:
   ...
}

The connection is going to be initialized in the source file Cache.cpp before the class methods:

...
pqxx::connection
Cache::dbCon("user=postgres password=xxxx dbname=mydb hostaddr=127.0.0.1 port=5432");

Cache::Cache() { ... }
...

The connection constructor could throw an exception. How do I catch that?
Java allows a static block to handle that, C++ AFAIK doesn't.
I was googleing it but could not find anything; neither in FAQ's. Its probably trivial so please be nice to me. ;-)

Thanks for your help,
-- Bernd



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux