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

Exception handling

hamid3252
Beginner
668 Views
Hi,

Would you please let me know how I can catch exceptions in Intel Fortran?I have been working with C++ and Java and I expect there should be a way similar to what exists in C++/Java to handle exceptions. Please let me know how to handle the situations.
Thank you,
Hamidreza,
0 Kudos
2 Replies
TimP
Honored Contributor III
668 Views
Fortran doesn't have a complete signal handling facility parallel to C++. I've seen applications which use Fortran and C++ in a highly intertwined way, with the objective of doing this. The serious non-portabilities are mostly within the C++ portion.
Fortran ieee_arithmetic facility provides for numerical exception handling. An f2003 version of the examples in Reid's earlier paper is included in the textbook "Fortran 95/2003 explained."
There are several good presentations at the top of my web search results; perhaps you could look at some and refine your extremely broad question.
0 Kudos
jimdempseyatthecove
Honored Contributor III
668 Views

I would suggest you write your Fortran code with assertions (for memory allocation errors, argument errors etc...), such that the assert sets an error condition known to your interface. Then have your C++/Java code call a shell C++/ Java function which then calls the Fortran function/subroutine and tests the known error condition and throws an error if necessary

void YourExposedInterface()
{
hiddenExceptionCode = NoExceptionOccured;
YourHiddenInterface();
if(hiddenExceptionCode == NoExceptionOccured)
return;
throw(hiddenExceptionCode);
}

The degree of which errors are caught will depend upon the degree of your exception coding in your Fortran library.

Note, you can also have your Fortran code call C++/Java support routines (via similar shell function technique) that then captures exception conditions that are otherwise difficult to handle in Fortran.

Jim Dempsey

0 Kudos
Reply