Exceptions do not exist in Fortran so there is no Exception handling. But the external file handling statements can now take optional iostat and iomsg clauses.
iostat is an integer which returns a non-zero value if there is an error but the execution will not stop.
You can add them to the open command in the Fortran code:integer :: my_iostatcharacter (256) :: my_iomsgopen (unit=1,status="unknown",file=filename,form="unformatted",iostat=my_iostat, iomsg=my_iomsg)if (my_iostat/=0) then ! put some values in params that you could use to identify the error in Pythonelse ! read the fileend if
In the python code you must check if the returned values match the ones you defined for error otherwise the file was read without problems.