Fortran

Guide To Learn

Error Handling with iostat

This example demonstrates how to handle errors using the iostat specifier in Fortran.

fortranCopy codeprogram error_handling
    implicit none
    integer :: i, ios
    real :: value

    open(unit=10, file='data.txt', status='old', iostat=ios)
    if (ios /= 0) then
        print *, 'Error opening file!'
        stop
    end if

    do
        read(10, *, iostat=ios) value
        if (ios /= 0) exit
        print *, 'Read value: ', value
    end do

    close(10)
end program error_handling
Error Handling with iostat

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top