When an exception occurs I would like to terminate abnormally my program. Right now, when an exception happens a write
statement with an explanatory sentence is called, and then a stop
statement is called.
I am debugging the program with idb
(intel debugger), when the exception happens I get the write
statement, but idb
treats the program as terminated normally. I would like that when the exception happens the program is terminated abnormally and so that I can look to the memory with backtrace
in the place where the exception happened.
I have tried changing stop
in stop 1
, so that a non zero value is returned, but this doesn't work
EDIT:
I have implemented the solution in one of the answer:
interface
subroutine abort() bind(C, name="abort")
end subroutine
end interface
print *,1
call abort()
print *,2
end
with this solution I still do not get any backtrace when I am using ifort 13.0.1
, but this works perfectly with ifort 14.0.2
.
I have resorted to use idb
instead of gdb
, because often the latter cannot read the values of allocatable arrays in fortran
.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…