Re: static member initialization in a try/catch block?

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

 



Bernd Prager <bernd@xxxxxxxxx> writes:

> 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. ;-)


This isn't a gcc question.  It's a C++ question.  You may get a better
answer if you ask in a C++ language forum.

As far as I know there is no way in C++ to catch an exception thrown
by the constructor of a global variable.

Ian


[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