- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Let's assume I have a DLL which exports the following subroutine:
I,J are input/output parameters; STATUS is a flag indicating successful call to the subroutine or not.
This subroutine calls many other internal subroutines in this DLL. Now, if an error condition occurs (and is detected) in one of these internal subroutines, is there a convenient way to come back to the main subroutine toset my flag STATUS to -1 for instance? Obviously I canpass STATUS as an argument for all my internal subroutines, and then use a RETURN statement in each of these, but there are many, many of them...
Is there another way around this tedious process?
Thanks,
Olivier
[fortran]SUBROUTINE MY_MAIN_SUB(I,J,STATUS) !DEC$ ATTRIBUTES DLLEXPORT :: MY_MAIN_SUB
! ... do a lot of work here ...
END SUBROUTINE MY_MAIN_SUB [/fortran]
I,J are input/output parameters; STATUS is a flag indicating successful call to the subroutine or not.
This subroutine calls many other internal subroutines in this DLL. Now, if an error condition occurs (and is detected) in one of these internal subroutines, is there a convenient way to come back to the main subroutine toset my flag STATUS to -1 for instance? Obviously I canpass STATUS as an argument for all my internal subroutines, and then use a RETURN statement in each of these, but there are many, many of them...
Is there another way around this tedious process?
Thanks,
Olivier
Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Presumably all your DLL routines are in a module, which can have its own status flag (distinct from the STATUS passed output argument) with modular scope, call it mod_status, which only needs to be defined once so you don't have to push it on the stack as an added argument for all subroutine calls. To track errors (each with its own mod_status value), every call to an internal DLL routine would be immediately followed by
IF (mod_status /= no_error) RETURN
which would clean out the call stack all the way back to the entry routine, whereupon STATUS = mod_status would be set on exit. This provides a nice way to improve on simply "an error occured" by returning the detailed error type or locus.
IF (mod_status /= no_error) RETURN
which would clean out the call stack all the way back to the entry routine, whereupon STATUS = mod_status would be set on exit. This provides a nice way to improve on simply "an error occured" by returning the detailed error type or locus.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Depending on how comfortable you are using WinAPI routines ormixing C/C++ and Fortran, you can try something like this:
[cpp]void CallTheFortranFunction() { bool bDone=false; CONTEXT c; RtlCaptureContext (&c); if(!bDone) { bDone=true; FortranFunction(); // To quickly abort FortranFunction, have it call // SetThreadContext(GetCurrentThread(),&c); } }[/cpp]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, that's clever; I do something very similar to wind up communications threads. However, SetThreadContext() calls would have to be added at each error check, and the amount of work, both in recoding and in runtime, would not be less than simply using a module-scoped flag with a RETURN chain.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Very true. The only wayI found to somewhat"automate" the process is to deliberately let exceptions be raised and handled.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanksfor the replies. It looks like I am not going to avoid having to edit all these subroutines after all. The solution I have is close to what Paul suggested.
Thanks again!
Olivier
Thanks again!
Olivier
![](/skins/images/54BF544B471F3F61DFD338F1D58F9426/responsive_peak/images/icon_anonymous_message.png)
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page