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

Catching RaiseException from Fortran DLL in C#

siekiew
Beginner
1,400 Views

Test subroutine that raise and exception in Fortran DLL

SUBROUTINE TESTSEH()
!DEC$ ATTRIBUTES DLLEXPORT::TESTSEH
USE kernel32
call RaiseException(150, 0 , 0, 0)
END SUBROUTINE TESTSEH

And in C#,

try
{
TESTSEH();
}
catch (SEHException ex)
{
int ec = Marshal.GetExceptionCode();

}

In this case, the ec returns 150, which is expected.

Butit would be good to be able to return more information through the RaiseException apart from the ExceptionCode.

The RaiseExcpetion has the following parameters:

void RaiseException(
DWORD dwExceptionCode,
DWORD dwExceptionFlags,
DWORD nNumberOfArguments,
const ULONG_PTR* lpArguments
);

How can I make use of lpArguments to return information such as message string or integer? How to capture those information in C#?

Thank you.

0 Kudos
4 Replies
g_f_thomas
Beginner
1,400 Views

AFAIK this is as good as it gets in C# handling of unmanaged code exceptions. If you want a traceback you have to handle the exception in Fortran (via unmanaged C++ since Fortrandoesn't do exception handling, except in f03 for those of the ieee fp variety).

Gerry

0 Kudos
siekiew
Beginner
1,400 Views

Thank you Gerry for responding to my question.Where can I get more information onhandling exception in Fortran via unmanaged C++? Any example would be very helpful.

Thank you.
David

0 Kudos
g_f_thomas
Beginner
1,400 Views

It depend on which Fortran compiler you use. CVF 6+ has numerous working samples on SEH but whether they work on IVF is another matter. Specifically, they don't work with ivf 10.1.013, they may or may not work with 10.1.014 but even if they do, don't back on them working on releases beyond that. I got them to work with ivf 9.1.There was a thread called Exception handling under IVF in Q4 of 2006 (or 7, if forget which) dealing with this issue but I see nothing to suggest that IVF has changed to amend its flaws in respect to SEH.

Gerry

0 Kudos
siekiew
Beginner
1,400 Views

I am using IVF 10.1.011. I manage to get to the thread Exception handling under IVF. I need a bit of time to go through. Thank you.

0 Kudos
Reply