Click here to Skip to main content
15,881,709 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
I am using P/Invoke calls to Fortran dynamic link libraries (DLLs, compiled with Intel Fortran compiler). As these Fortran libraries are currently being under development, I quite often get Fortran run-time errors which display a message box containing the error information.

The problem is that as soon as I click 'OK' on those message-boxes my own C# (.Net Framework 4.0) application shuts-down making them fatal to my application as well.

Furthermore, I am utilizing a global error handling mechanism in my C# code which traps all .Net errors and logs them into an ASCII file. Off-course since I cannot trap the Fortran generated errors no logging on my end occurs in such cases.

So my questions are: a) can I somehow get away with the P/Invoke fatal error crashes (ie keep my application running after they occur) and b) is there any way that I can tunnel the external P/Invoke error information into my own managed C# error handling routines?

EDIT:

More on the error: I am already utilizing try, catch, finally blocks within which I perform the P/Invokes. Unfortunately, ever since I posted this question I received new DLL versions that fixed the error I encountered last. I have kept though a screenshot out of which I can provide further information about what those message-boxes look like.

The Fortran .DLL files are 32-bit and the caption on the error message reads
'Intel(r) Visual Fortran run-time error', then the body of the message box reads

'forrtl: severe (408): fort: (3): Subscript #1 of the array PPLOW has value 0 which is less than the lower bound of 1'.

Now I know what that error means, fortran is using 1-based indexing whilst .Net as we all know uses 0-based indexing and that's fine, I provide this information to the Fortran library developers and they fix their routines. I would like though to keep these errors from crashing my application as well.
Posted
Updated 5-Nov-15 17:19pm
v3
Comments
Philippe Mori 5-Nov-15 13:05pm    
What king of message you get? I don't know much about Fortran... Does it uses windows exception? Or its owns mecanism? In that case, you woull have to handle them in the library itself...
Philippe Mori 5-Nov-15 13:07pm    
From where the error message is displayed? Look at the call stack. Is it code in Fortran library? In .Net framework? In your application?
Philippe Mori 5-Nov-15 13:10pm    
Does the Intel compiler exception are based on Win32 exception?

1 solution

One way which comes to mind (and it may not be best practice tho)... may be to wrap the P/Invoke calls in a try/catch/finally block to handle with any exceptions generated by the calls.

Furthermore, any access/calls to the libraries could be placed into its own central class and error handling could be controlled there.

Tho, I’m not a big user of P/Invoke calls, so others may have some better advice.

Once the exception is caught in the catch() block, normal .NET error handling can kick in and you can build it into your current logging mechanism.

Like I said, it may not be the best solution, but it could be a start :)

-DB
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900