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

C# - Fortran 11.1 - Try Catch (in C#) not being caught when Fortran error is encountered.

aggiedad
Beginner
1,277 Views

Hello,

I am a C# developer with little experience in Fortran. I have inherited a C# application which access a Fortran DLL (written / compiled in Intel Visual Fortran Compiler version 11.1).

Everything works fine until an error in the Fortran is encountered.

I have placed a number of Try Catch blocks around the Fortran calls, but the Fortran does not return / see them so the application displays an error and stops processing. I have searched the Internet for a solution but have not really found an answer, most being a few years old.

Can someone point me in the right direction on what needs to be doneto allow errors in the fortran code to return back to the C# application so they can be caught and processed there?

Thank you!

Eric

0 Kudos
6 Replies
Steven_L_Intel1
Employee
1,277 Views
To the best of my knowledge, you can't do this at present. Errors reported by the Fortran library are not signaled exceptions - they are handled within the library and not propagated. In a future release (next year), we expect to offer a way to register a user routine to be called when a Fortran error is to be reported.
0 Kudos
aggiedad
Beginner
1,277 Views

Thanks for your response Steve

As a solution, could the Fortran code be modified to handle the error on that side, then pass these exceptions and simply return a known code that I could grab on the C# side and Know there was an error?

Thanks again!

Eric

0 Kudos
Steven_L_Intel1
Employee
1,277 Views
The solution we have come up with is very general - you can make it work most any way you want, including raising an exception that gets caught by a handler. But there is also the Fortran standard IOSTAT= that can prevent Fortran from doing anything other than returning an error code. You'd then have to test it. It's modeled on the VMS LIB$ESTABLISH method of registering exception handlers.

Which kind of error are you seeing that you want to catch, and what do you want to do with it once it is caught?
0 Kudos
aggiedad
Beginner
1,277 Views

Hello Steve, Thanks again.

I know one is the 2GB boundary that I have seen on the internet. I also get other errors an error that there is No Disk in the Drive \device\harddrive2\DR2 Cancel, Try Again, Continue. Another is System.AccessViolationException.

Depending on the parameters that person enters is where I think I get the 2GB limit exception. This application is a model that pulls in a significant amount of data and takes well over 10 30 minutes to run normally. It seems to work fine, has been running for a few years now as a stand-alone. I guess when they hit the errors they simply know to change something. I am now attempting to put it in a console application which is launched from a dedicated system. However, if the Fortran code simply hangs on me that is a problem. Does this help at all?

Since I am not a good Fortran developer and it is not my code, I am not sure what to do with your suggestion, but I will Google it and see if I can figure it out.

Thanks again!

Eric

0 Kudos
Steven_L_Intel1
Employee
1,277 Views
Well, it's not going to help you. The access violation is not really something you can recover from. Our user-handler routine would at least let you "do something" rather than just die.

The "No disk" problem I'm not sure what you can do with, nor what triggers it. It is a Windows prompt that you can't control. As for 2GB limit, at best you'll get an error when trying to allocate memory. It should not cause a hang.
0 Kudos
aggiedad
Beginner
1,277 Views
Thanks again, I need a few days to discuss with others at this point...

Eric
0 Kudos
Reply