Project

General

Profile

Exception handling in Mac OS X

Added by Charles Myers over 12 years ago

Hi guys,

I have an issue with the exception handling on the Mac.
I'm new to the Mac and get a little stumped when the behvior differs from Windows.

My problem is that I have a try/catch block tht looks something like;

try {
do some exiv2 stuff
}
catch (Exiv2::Error &error) {
store error message from error.what().c_str()
continue doing stuff.
}

However on the Mac my application hangs if there is an exception.
If I run the app from the command line I get:

terminate called after throwing an instance of 'Exiv2::Error'
what(): <error message>
Abort trap

I want to catch the exception and do something with it.
Any help appriciated.

charlie


Replies (5)

RE: Exception handling in Mac OS X - Added by Robin Mills over 12 years ago

Charlie

I'll have to investigate this. Andreas might have a super smart inspired idea of course.

Can you send me your code and project (a zip or dmg or whatever's convenient) and your makefile(s) or XCode project or whatever you use to build. You can post the archive here OR if you want to keep your code confidential, then email it directly to me. (I believe you've got my email address and it's in exiv2/msvc/README-MSVC.txt)

It's 9:30am in California at the moment so I'm at work. I'll investigate this evening at home.

Robin

RE: Exception handling in Mac OS X - Added by Robin Mills over 12 years ago

Charlie

I made a few little changes to exiv2/samples/exifprint.cpp (I attach exifprint.cpp.changed) and rebuilt it:

538 /Users/rmills> cd ~/gnu/exiv2/samples

539 /Users/rmills/gnu/exiv2/samples> make exifprint
g++ -O2 -fvisibility=hidden -fvisibility-inlines-hidden -Wall -Wcast-align -Wpointer-arith -Wformat-security -Wmissing-format-attribute -Woverloaded-virtual -W -MMD `pkg-config exiv2 --cflags` -c -o exifprint.o exifprint.cpp
../libtool --mode=link g++ `pkg-config exiv2 --libs` -o exifprint exifprint.o
g++ -Wl,-framework -Wl,CoreFoundation -o exifprint exifprint.o -Wl,-bind_at_load -L/opt/local/lib /opt/local/lib/libexiv2.dylib -L/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_graphics_exiv2/work/exiv2-0.18/xmpsdk/src /opt/local/lib/libintl.dylib -lc /opt/local/lib/libiconv.dylib -lz /opt/local/lib/libexpat.dylib

540 /Users/rmills/gnu/exiv2/samples> exifprint ~/nosuchfile
Caught Exiv2 exception '/Users/rmills/nosuchfile: Failed to open the data source: No such file or directory (2)'
exifprint.cpp is alive and kicking

541 /Users/rmills/gnu/exiv2/samples> exifprint ~/.profile
Caught Exiv2 exception '/Users/rmills/.profile: The file contains data of an unknown image type'
exifprint.cpp is alive and kicking

542 /Users/rmills/gnu/exiv2/samples> exifprint ~/P/WesternStatesTraining/Sunday/Robin\ on\ the\ trail.jpg
Exif.Image.Make 0x010f Ascii 6 Canon
... stuff deleted ...
Exif.Thumbnail.JPEGInterchangeFormatLength 0x0202 Long 1 5985
exifprint.cpp is alive and kicking

543 /Users/rmills/gnu/exiv2/samples>

Everything behaves as I would expect! Not a hang in sight.

I think your issue may be related to your build environment/linking. Are you using XCode and its (secret) Mac Magic?

RE: Exception handling in Mac OS X - Added by Andreas Huggel over 12 years ago

Hi Charlie,

Misbehaving exceptions usually have something to do with the "visibility" feature (see #523).

To confirm if that's also the case here, can you recompile the exiv2 library with an additional --disable-visibility option to the configure script and see if your application works with that?

If it does, turn it back on and we'll investigate where the incompatibility is.

Andreas

RE: Exception handling in Mac OS X - Added by Charles Myers over 12 years ago

Cheers guys,

I posted just before finishing here yesterday so picking this up now.

I've added --disable-visibility and all is well.
What is the impact of disabling this flag? Can I keep in disabled?

charlie

RE: Exception handling in Mac OS X - Added by Andreas Huggel over 12 years ago

Firstly, can you please provide some info about your build environment for future reference here? Which OSX version/g++ do you have, how do you compile, etc.

Then, yes, you can keep it disabled. The functionality of the library remains the same. See the Exiv2 feature I linked to earlier and this page for details about what it does.

Of course it would be good to get to the bottom of this particular case too and find out what's the root cause of the problem. For all you know, it might turn out to be an Exiv2 bug. Some ideas:

  • Check if the library compiled with the standard visibility-hidden options exports the Exiv2::Error symbol (nm -C -D <library>.so)
  • Create a small reproducer for your problem to experiment with (I don't have a Mac so won't be able to assist)
  • Check if certain compiler optimization settings trigger the problem (e.g., after running configure, remove the -O2 from config/config.mk or try with -O2, with -fvisibility=hidden but without -fvisibility-inlines-hidden) - there have been such issues before
  • Check if this may be a Mac OSX gcc bug as described here or here - does adding the option -no_dead_strip_inits_and_terms help?

Andreas

    (1-5/5)