RE: Unable to catch Gdk::PixbufError
- From: Murray Cumming <murrayc murrayc com>
- To: J B C Engelen ewi utwente nl
- Cc: gtkmm-list gnome org
- Subject: RE: Unable to catch Gdk::PixbufError
- Date: Sun, 18 Nov 2007 21:12:57 +0100
On Sun, 2007-11-18 at 20:39 +0100, J B C Engelen ewi utwente nl wrote:
> I have written a simple program to demonstrate the problem. It is given
> below. The program must be run like: pixbuferror.exe test.jpg.
So you appear to be using Windows. I wonder if that is relevant. How did
you install gtkmm? What version do you have, on what version of Windows?
> 1. If test.jpg does not exist, I get this : "terminate called after
> throwing an instance of 'Glib::FileError'"
> 2. If test.jpg does exit but is not a valid file : "terminate called
> after throwing an instance of 'Glib::Error'"
> 3. If test.jpg is valid, the program shows "Succes!!!" indicating that
> it at least did not crash. It does show some glibmm warnings but that is
> because things are probably not initialised properly.
It works for me:
murrayc murrayc-desktop:~$ g++ pixbuf_exception_test.cc `pkg-config
gtkmm-2.4 --libs --cflags`
murrayc murrayc-desktop:~$ ./a.out test.png
** Message: caught Glib::FileError
> Since I really do not know how to initialise gdk and friends properly, I
> have stopped trying and hope you can work with this little program. In
> any case, the program does not catch exceptions which I find really
> strange.
You just need to instantiate a Gtk::Main. It doesn't seem to be
necessary in this case but I have done that in the attached improved
version of this test case.
--
murrayc murrayc com
www.murrayc.com
www.openismus.com
// Build with
// g++ pixbuf_exception_test.cc `pkg-config gtkmm-2.4 --libs --cflags`
#include <gtkmm.h>
#include <iostream>
int main(int argc, char **argv) {
Gtk::Main main(argc, argv);
Glib::ustring fileName;
if(argc > 1)
fileName = argv[1];
//Get some image info. Smart pointer does not need to be deleted
Glib::RefPtr<Gdk::Pixbuf> img;
try
{
img = Gdk::Pixbuf::create_from_file(fileName);
}
catch (const Glib::FileError& ex)
{
std::cerr << "caught Glib::FileError: " << ex.what() << std::endl;
return -1;
}
catch (const Gdk::PixbufError& ex)
{
std::cerr << "caught Gdk::PixbufError:" << ex.what() << std::endl;
return -1;
}
catch (...)
{
g_message("Caught ... ");
return -1;
}
g_message("Success!!!");
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]