Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Throwing C++ exceptions in FORTRAN

dan_hensley
Beginner
868 Views

Hi,

I'm just getting back into FORTRAN development after about 10 years of being away. My first task is to port a FORTRAN program from HPUX to Windows, and change it from a standalone executable into a DLL. So far things are going well, but I've run into one snag.

There are some error-handling routines in FORTRAN that display an error message and then call EXIT. This was fine as a standalone executable, but this is not fine with the DLL. I am calling the DLL from some other C/C++ code.

My thought on handling this was instead of calling EXIT, I write a C++ routine that I call that throws an exception, that I can catch from the function that calls the FORTRAN code. However, this does not appear to be working. I get a message saying that I'm getting an unexpected unknown exception, instead of the one I'm actually throwing.

Is what I am trying to do even possible? I've been through the documentation several times and have searched these forums and Google, and so far have not found an answer.

Thanks,

Dan

0 Kudos
2 Replies
jimdempseyatthecove
Honored Contributor III
868 Views

I haven't done this myself Jugoslav or Steve might have done this. But if I were to roll my own exception routine I would write a C++ shell function that has exception handling and the body does something like:

YourEnvelopeFunction

push signature onto stack
call the Fortran Function
test signature for exception
if(error) throwException
return

YourEXITreplacement.ASM

search stackupwards for signature
set stack pointer accordingly
insert exception code into signature
return (to your C++ envelope)

Jim Dempsey

0 Kudos
dan_hensley
Beginner
868 Views

Thanks for the quick reply. Turns out it was a stupid error on my part. I was compiling the wrong routine. When I got everything straight, the exception handling worked just as I was hoping it would.

Thanks,
Dan

0 Kudos
Reply