C++ API: Which exception for openDataSet?

Hello,

I'm doing my first steps with the C++ API, and there's one problem I can't conquer:

I'm trying to test if a dataset exists using the following code:

        try{
            std::cout << "Trying to open DS..." << endl;
            H5::DataSet foo = fg_p->openDataSet(location);
        }

        catch(H5::GroupIException e) {
            std::cout << "GroupIException" << endl;
        }
        catch(H5::FileIException e) {
            std::cout << "FileIException" << endl;
        }
        catch (...) {
            std::cout << "Caught by ..." << endl;
            return false;
        }
        return true;

fg_p is a pointer to a CommonFG object, location is a string here.

For datasets that exist it works alright, but for a non-existing dataset, only
the catch(...) is triggered. What would be the correct exception to catch here?

Also is there a way to suppress all the HDF5-DIAG output that I get?

Thanks,
Daniel

Hi Daniel,

fg_p must point to either a H5File or Group object, not CommonFG.
I hope that helps.

Binh-Minh

···

-----Original Message-----
From: hdf-forum-bounces@hdfgroup.org [mailto:hdf-forum-bounces@hdfgroup.org]
On Behalf Of Daniel Hornung
Sent: Wednesday, January 26, 2011 11:51 AM
To: hdf-forum@hdfgroup.org
Subject: [Hdf-forum] C++ API: Which exception for openDataSet?

Hello,

I'm doing my first steps with the C++ API, and there's one problem I can't
conquer:

I'm trying to test if a dataset exists using the following code:

        try{
            std::cout << "Trying to open DS..." << endl;
            H5::DataSet foo = fg_p->openDataSet(location);
        }

        catch(H5::GroupIException e) {
            std::cout << "GroupIException" << endl;
        }
        catch(H5::FileIException e) {
            std::cout << "FileIException" << endl;
        }
        catch (...) {
            std::cout << "Caught by ..." << endl;
            return false;
        }
        return true;

fg_p is a pointer to a CommonFG object, location is a string here.

For datasets that exist it works alright, but for a non-existing dataset,
only
the catch(...) is triggered. What would be the correct exception to catch
here?

Also is there a way to suppress all the HDF5-DIAG output that I get?

Thanks,
Daniel

Hi Binh-Minh,

fg_p is a pointer of type CommonFG, but points to an H5File or Group object, of
course (CommonFG is abstract, so this can not be the problem anyway). Sorry if
I was not clear enough on this.

The output is as follows, by the way:

Trying to open DS...
HDF5-DIAG: Error detected in HDF5 (1.8.5-patch1) thread 0:
  #000: H5D.c line 320 in H5Dopen2(): not found
    major: Dataset
    minor: Object not found
  #001: H5Gloc.c line 480 in H5G_loc_find(): can't find object
    major: Symbol table
    minor: Object not found
  #002: H5Gtraverse.c line 964 in H5G_traverse(): internal path traversal failed
    major: Symbol table
    minor: Object not found
  #003: H5Gtraverse.c line 759 in H5G_traverse_real(): traversal operator failed
    major: Symbol table
    minor: Callback failed
  #004: H5Gloc.c line 435 in H5G_loc_find_cb(): object 'datum' doesn't exist
    major: Symbol table
    minor: Object not found
...
Does "datum" exist? No <- This line comes from somewhere else in the code
and means that false was returned.

Cheers,
Daniel

···

On 2011-01-26 19:02, Binh-Minh Ribler wrote:

Hi Daniel,

fg_p must point to either a H5File or Group object, not CommonFG.
I hope that helps.

Binh-Minh

Hi Daniel,

···

On Jan 27, 2011, at 2:28 AM, Daniel Hornung wrote:

On 2011-01-26 19:02, Binh-Minh Ribler wrote:

Hi Daniel,

fg_p must point to either a H5File or Group object, not CommonFG.
I hope that helps.

Binh-Minh

Hi Binh-Minh,

fg_p is a pointer of type CommonFG, but points to an H5File or Group object, of
course (CommonFG is abstract, so this can not be the problem anyway). Sorry if
I was not clear enough on this.

The output is as follows, by the way:

Trying to open DS...
HDF5-DIAG: Error detected in HDF5 (1.8.5-patch1) thread 0:
#000: H5D.c line 320 in H5Dopen2(): not found
   major: Dataset
   minor: Object not found
#001: H5Gloc.c line 480 in H5G_loc_find(): can't find object
   major: Symbol table
   minor: Object not found
#002: H5Gtraverse.c line 964 in H5G_traverse(): internal path traversal failed
   major: Symbol table
   minor: Object not found
#003: H5Gtraverse.c line 759 in H5G_traverse_real(): traversal operator failed
   major: Symbol table
   minor: Callback failed
#004: H5Gloc.c line 435 in H5G_loc_find_cb(): object 'datum' doesn't exist
   major: Symbol table
   minor: Object not found
...
Does "datum" exist? No <- This line comes from somewhere else in the code
and means that false was returned.

  I'm not certain if it is expressed in the C++ API wrappers, but you probably want to use the H5Lexists() routine for this sort of check.

  Quincey

Hi Daniel,

···

On Jan 27, 2011, at 2:28 AM, Daniel Hornung wrote:

On 2011-01-26 19:02, Binh-Minh Ribler wrote:

Hi Daniel,

fg_p must point to either a H5File or Group object, not CommonFG.
I hope that helps.

Binh-Minh

Hi Binh-Minh,

fg_p is a pointer of type CommonFG, but points to an H5File or Group object, of
course (CommonFG is abstract, so this can not be the problem anyway). Sorry if
I was not clear enough on this.

The output is as follows, by the way:

Trying to open DS...
HDF5-DIAG: Error detected in HDF5 (1.8.5-patch1) thread 0:
#000: H5D.c line 320 in H5Dopen2(): not found
  major: Dataset
  minor: Object not found
#001: H5Gloc.c line 480 in H5G_loc_find(): can't find object
  major: Symbol table
  minor: Object not found
#002: H5Gtraverse.c line 964 in H5G_traverse(): internal path traversal failed
  major: Symbol table
  minor: Object not found
#003: H5Gtraverse.c line 759 in H5G_traverse_real(): traversal operator failed
  major: Symbol table
  minor: Callback failed
#004: H5Gloc.c line 435 in H5G_loc_find_cb(): object 'datum' doesn't exist
  major: Symbol table
  minor: Object not found
...
Does "datum" exist? No <- This line comes from somewhere else in the code
and means that false was returned.

  I'm not certain if it is expressed in the C++ API wrappers, but you probably want to use the H5Lexists() routine for this sort of check.

  Quincey

Hi Daniel,

As Quincey said, H5Lexist would be a better way, but the C++ API does not
have a wrapper for that yet. You could call H5Lexist directly, passing in
<object>.getId().

If you continue using your current approach, you will need fg_p to be of
type Group so that the correct exception, GroupIException, would be thrown.

Binh-Minh

···

-----Original Message-----
From: hdf-forum-bounces@hdfgroup.org [mailto:hdf-forum-
bounces@hdfgroup.org] On Behalf Of Daniel Hornung
Sent: Thursday, January 27, 2011 3:28 AM
To: HDF Users Discussion List
Subject: Re: [Hdf-forum] C++ API: Which exception for openDataSet?

On 2011-01-26 19:02, Binh-Minh Ribler wrote:

Hi Daniel,

fg_p must point to either a H5File or Group object, not CommonFG.
I hope that helps.

Binh-Minh

Hi Binh-Minh,

fg_p is a pointer of type CommonFG, but points to an H5File or Group
object, of
course (CommonFG is abstract, so this can not be the problem anyway).
Sorry if
I was not clear enough on this.

The output is as follows, by the way:

Trying to open DS...
HDF5-DIAG: Error detected in HDF5 (1.8.5-patch1) thread 0:
#000: H5D.c line 320 in H5Dopen2(): not found
   major: Dataset
   minor: Object not found
#001: H5Gloc.c line 480 in H5G_loc_find(): can't find object
   major: Symbol table
   minor: Object not found
#002: H5Gtraverse.c line 964 in H5G_traverse(): internal path traversal
failed
   major: Symbol table
   minor: Object not found
#003: H5Gtraverse.c line 759 in H5G_traverse_real(): traversal operator
failed
   major: Symbol table
   minor: Callback failed
#004: H5Gloc.c line 435 in H5G_loc_find_cb(): object 'datum' doesn't
exist
   major: Symbol table
   minor: Object not found
...
Does "datum" exist? No <- This line comes from somewhere else in the
code
and means that false was returned.

Cheers,
Daniel

Hi again, Daniel,

A little correction to my previous message:
"If you continue using your current approach, you will need fg_p to be of
type Group so that the correct exception, GroupIException, would be thrown."

Should be:
"If you continue using your current approach, you will need fg_p to be of
type Group or H5File so that the correct exception, GroupIException or
FileIException, would be thrown."

I'm sure you could figure it out, but it makes me feel better saying it. :slight_smile:
Binh-Minh

···

-----Original Message-----
From: hdf-forum-bounces@hdfgroup.org [mailto:hdf-forum-
bounces@hdfgroup.org] On Behalf Of Binh-Minh Ribler
Sent: Thursday, January 27, 2011 9:13 AM
To: 'HDF Users Discussion List'
Subject: Re: [Hdf-forum] C++ API: Which exception for openDataSet?

Hi Daniel,

As Quincey said, H5Lexist would be a better way, but the C++ API does not
have a wrapper for that yet. You could call H5Lexist directly, passing in
<object>.getId().

If you continue using your current approach, you will need fg_p to be of
type Group so that the correct exception, GroupIException, would be thrown.

Binh-Minh

-----Original Message-----
From: hdf-forum-bounces@hdfgroup.org [mailto:hdf-forum-
bounces@hdfgroup.org] On Behalf Of Daniel Hornung
Sent: Thursday, January 27, 2011 3:28 AM
To: HDF Users Discussion List
Subject: Re: [Hdf-forum] C++ API: Which exception for openDataSet?

On 2011-01-26 19:02, Binh-Minh Ribler wrote:

Hi Daniel,

fg_p must point to either a H5File or Group object, not CommonFG.
I hope that helps.

Binh-Minh

Hi Binh-Minh,

fg_p is a pointer of type CommonFG, but points to an H5File or Group
object, of
course (CommonFG is abstract, so this can not be the problem anyway).
Sorry if
I was not clear enough on this.

The output is as follows, by the way:

Trying to open DS...
HDF5-DIAG: Error detected in HDF5 (1.8.5-patch1) thread 0:
#000: H5D.c line 320 in H5Dopen2(): not found
   major: Dataset
   minor: Object not found
#001: H5Gloc.c line 480 in H5G_loc_find(): can't find object
   major: Symbol table
   minor: Object not found
#002: H5Gtraverse.c line 964 in H5G_traverse(): internal path traversal
failed
   major: Symbol table
   minor: Object not found
#003: H5Gtraverse.c line 759 in H5G_traverse_real(): traversal operator
failed
   major: Symbol table
   minor: Callback failed
#004: H5Gloc.c line 435 in H5G_loc_find_cb(): object 'datum' doesn't
exist
   major: Symbol table
   minor: Object not found
...
Does "datum" exist? No <- This line comes from somewhere else in the
code
and means that false was returned.

Cheers,
Daniel

_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@hdfgroup.org
http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org

--
Internal Virus Database is out-of-date.
Checked by AVG.
Version: 7.5.549 / Virus Database: 270.9.0/1778 - Release Date: 11/9/2008
2:14 PM

Quincey wrote:

but you probably want to use the H5Lexists() routine for this sort of check.

If you continue using your current approach, you will need fg_p to be of type
Group so that the correct exception, GroupIException, would be thrown.

Hi,

I think I will use the C API function thank you both for pointing this out. But
I still don't get the current behaviour.

I try to catch any FileIException, which is thrown according to:

"terminate called after throwing an instance of 'H5::FileIException'"

The backtrace is:

(gdb) bt
#0 0x92525e42 in __kill ()
#1 0x92525e34 in kill$UNIX2003 ()
#2 0x9259823a in raise ()
#3 0x925a4679 in abort ()
#4 0x91c69005 in __gnu_cxx::__verbose_terminate_handler ()
#5 0x91c6710c in __gxx_personality_v0 ()
#6 0x91c6714b in std::terminate ()
#7 0x91c67261 in __cxa_throw ()
#8 0x0133dbe6 in H5::H5File::throwException ()
#9 0x016a4454 in H5::CommonFG::openDataSet ()
#10 0x016a4582 in H5::CommonFG::openDataSet ()

So obviously H5File throws a FileIException indeed in its overloading of
CommonFG's abstract throwException().

One possibility to explain the issue may be dynamic linking problems, maybe, so
that the type checking during the catch phase wrongly does not recognize the
correct catch clause. I will look more into this direction now.

Greetings,
Daniel

···

On 2011-01-27 15:12, Binh-Minh Ribler wrote:

Hi everyone again,
the problem seems to be with the way the HDF5 library was compiled originally
indeed. The error occurred with hdf5 installed by macports on this OS X 10.5
system, it vanished when I compiled everything I needed myself.

I will probably file a bug report with macports against this issue.

Thanks again,
Daniel

···

On 2011-01-27 15:58, Daniel Hornung wrote:

One possibility to explain the issue may be dynamic linking problems, maybe, so
that the type checking during the catch phase wrongly does not recognize the
correct catch clause. I will look more into this direction now.