- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am calling a fortran function from C++ code in a try/catch block. For certain inputs, I get the following RTL error:
forrtl: severe (64): input conversion error, unit -5, file Internal Formatted Read
I would like to catch this error, and any others, in the C code and print a message like "the Fortran function had an error" to a file. The code is running remotely, so I don't want the RTL error window to come up.
My code for windowsis :
retval = putenv("FOR_DISABLE_DIAGNOSTIC_DISPLAY=TRUE");
try
{
retval = CHARMM(); // The fortran function
switch (retval) {
case 0: fprintf(stderr, "SUCCESS - Charmm exited with code %i.
", retval);
break;
.....
}
}
catch ( ... ) // Catch any errors
{
fprintf(stderr,"Charmm caused an exception!
");
}
Right now I am just looking for any exception, but if possible would like more information. This code has been able to catch other error caused by the function, stack overflow for example, but doesn't seem to catch any RTL errors. Is this possible?
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It actually comes from this Intel Forum thread:
http://softwareforums.intel.com/en-us/forums//topic/51696
Since exception handling is somewhat changed in IVF, I added
routine for_emit_diagnostic to Steve's SEHTEST example. It effectively
overrides built-in IVF mechanism (hardcoded call to for_emit_diagnostic
from the run-time library), by raising an exception explicitly itself
(EXCEPTION_ACCESS_VIOLATION is as good as any).
If your main program is in Fortran, you have to create some sort of
C++ wrappers with __try/__except around your (critical) function calls
and link them either to dll or to the main application.
| but where should this subroutine been called?
Nowhere -- it's called automagically when a IVF-handled exception
occurs. The code inserted by compiler into the code calls this
function. If it's in the RTL (default), it displays the annoying
message box; if it's your own, it does what you want.
(Take just a brief look into disassambly window for a line
with e.g. array operation, with "Array bounds checking" on).
The trick wasn't necessary with CVF -- it used to throw proper
exception on array bounds exceeded rather than emit the annoying
"Run-time error" message box.
| I've thus added the for_emit_diagnostic subroutine, which works fine
| in debug mode. Nevertheless, as soon as I compile my program in
| release mode I got the the following error: for_emit_diagnostic
| already defined in for_emit_diagnostic.obj :-((((((
Yes, I forgot to mention that glitch...
The "technique" in case is one of substituting default RTL routines;
as result, there are two copies of for_emit_diagnostic: yours and the
default RTL one.
If you link with a dll version of RTL, the thing works fine: your
routine always precedes RTL one. If you link with a static version
of RTL, you're likely to get the LNK2005 (already defined in...).
To overcome the problem, either link the dll with dll RTL (but you'll
have to redistribute libifcorert.dll), or add
/force:multiple
to the Properties/Linker/Additional options. (That might give you
a warning, but it will do the Right Thing).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Eventually, Intel should extend the Fortran compiler itself to handle Structured Exception Handling from within Fortran programs without resorting to C wrappers.John Reid made proposals in the past to add exception handling in Fortran using some block contructs. Intel could use that syntax as a starting point.
Best regards,
Jean Vezina
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I used force:multiple to solve the link error, but it is the original for_emit_diagnostic that executes (I still get the RTL error box).
I am using IVF 9.0 and can't open the sample project, so I'm doing my best to reproduce what you've done. Is the version an issue, or maybe I'm missing something?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
jeremy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Integer divide by zero you can catch. Floating divide by zero, by default, yields a NaN. You can specify /fpe:0 to make that an exception which you can catch. Similarly, floating overflow yields an Inf which /fpe:0 will make into an exception. Integer overflow is not detected in Fortran code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Integer divide by zero you can catch. Floating divide by zero, by default, yields a NaN. You can specify /fpe:0 to make that an exception which you can catch. Similarly, floating overflow yields an Inf which /fpe:0 will make into an exception. Integer overflow is not detected in Fortran code.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page