After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 390978 - Glib::Module does not report errors correctly
Glib::Module does not report errors correctly
Status: RESOLVED FIXED
Product: glibmm
Classification: Bindings
Component: general
2.12.x
Other Linux
: Normal normal
: ---
Assigned To: gtkmm-forge
gtkmm-forge
Depends on:
Blocks:
 
 
Reported: 2006-12-30 14:28 UTC by Johannes Schmid
Modified: 2007-04-16 15:53 UTC
See Also:
GNOME target: ---
GNOME version: 2.15/2.16



Description Johannes Schmid 2006-12-30 14:28:21 UTC
When I use this code:

  std::string filename = Glib::Module::build_path(COMPONENT_DIR, PREFIX + p_name);
  Glib::Module* module = new Glib::Module(filename);
  try
  {
    if (!module)
    {
      throw std::runtime_error(Glib::Module::get_last_error());
    }
  }
  catch(...) {...}

I get an empty error message, while this.

  std::string filename = Glib::Module::build_path(COMPONENT_DIR, PREFIX + 
    p_name);
  GModule* module = g_module_open(filename.c_str(), (GModuleFlags)0);
  try
  {
    if (!module)
    {
      throw std::runtime_error(g_module_error());
    }
  }
  catch(...) {...}

works fine!
Comment 1 Murray Cumming 2007-01-16 16:53:27 UTC
So I think you are just saying that get_last_error() returns an empty string. Could we have a simpler test case then?
Comment 2 Johannes Schmid 2007-04-16 14:09:18 UTC
OK, debugged a bit more and the solution is trivial:

if (!module) will check if the pointer to module is NULL. What I expected was (!module->operator bool()). IMHO this is a bit confusing but I doubt that we can change that. At least it is no "bug" of glibmm, it's just a bit ugly.

Usually it would be better to throw an exception with last_error as argument when the construction of module fails but exceptions in constructors are also non-trivial.
Comment 3 Murray Cumming 2007-04-16 15:32:57 UTC
If there is no Glib::Module operator bool() then we can add one. But I guess it's there and you just meant to do if (!(*module)).
Comment 4 Johannes Schmid 2007-04-16 15:40:31 UTC
Yes, there is an operator bool and if (!(*module)) will do what I expected.
Comment 5 Murray Cumming 2007-04-16 15:53:25 UTC
Feel free to add some text to the class documentation to make this clearer, particularly in this case of using new and a pointer. I assume that we can close this bug.