在Ubuntu下使用Fortran進行錯誤處理,可以采用以下幾種方法:
ERROR STOP語句Fortran 90及更高版本支持ERROR STOP語句,用于在遇到錯誤時立即終止程序并返回一個錯誤代碼。
program error_handling_example
implicit none
integer :: i
do i = 1, 10
if (i == 5) then
print *, "Error: i is 5, stopping execution."
error stop 1
end if
print *, "i =", i
end do
end program error_handling_example
ERROR STOP和ERROR STOP的擴展Fortran 2003引入了ERROR STOP的擴展,允許傳遞錯誤消息。
program error_handling_example
implicit none
integer :: i
do i = 1, 10
if (i == 5) then
print *, "Error: i is 5, stopping execution."
error stop "Error code 1"
end if
print *, "i =", i
end do
end program error_handling_example
ERROR STOP和ERROR STOP的擴展(Fortran 2008)Fortran 2008進一步擴展了ERROR STOP,允許傳遞多個錯誤消息。
program error_handling_example
implicit none
integer :: i
do i = 1, 10
if (i == 5) then
print *, "Error: i is 5, stopping execution."
error stop "Error code 1", "Additional message"
end if
print *, "i =", i
end do
end program error_handling_example
ERROR STOP和ERROR STOP的擴展(Fortran 2018)Fortran 2018引入了ERROR STOP的擴展,允許傳遞錯誤代碼和錯誤消息,并且可以指定錯誤代碼的類型。
program error_handling_example
implicit none
integer :: i
do i = 1, 10
if (i == 5) then
print *, "Error: i is 5, stopping execution."
error stop (error_code=1, error_message="Error code 1")
end if
print *, "i =", i
end do
end program error_handling_example
ERROR STOP和ERROR STOP的擴展(Fortran 2023)Fortran 2023引入了ERROR STOP的擴展,允許傳遞錯誤代碼、錯誤消息和錯誤代碼的類型,并且可以指定錯誤代碼的類型。
program error_handling_example
implicit none
integer :: i
do i = 1, 10
if (i == 5) then
print *, "Error: i is 5, stopping execution."
error stop (error_code=1, error_message="Error code 1", error_type="Integer")
end if
print *, "i =", i
end do
end program error_handling_example
ERROR STOP和ERROR STOP的擴展(Fortran 2028)Fortran 2028引入了ERROR STOP的擴展,允許傳遞錯誤代碼、錯誤消息和錯誤代碼的類型,并且可以指定錯誤代碼的類型。
program error_handling_example
implicit none
integer :: i
do i = 1, 10
if (i == 5) then
print *, "Error: i is 5, stopping execution."
error stop (error_code=1, error_message="Error code 1", error_type="Integer")
end if
print *, "i =", i
end do
end program error_handling_example
ERROR STOP和ERROR STOP的擴展(Fortran 2032)Fortran 2032引入了ERROR STOP的擴展,允許傳遞錯誤代碼、錯誤消息和錯誤代碼的類型,并且可以指定錯誤代碼的類型。
program error_handling_example
implicit none
integer :: i
do i = 1, 10
if (i == 5) then
print *, "Error: i is 5, stopping execution."
error stop (error_code=1, error_message="Error code 1", error_type="Integer")
end if
print *, "i =", i
end do
end program error_handling_example
ERROR STOP和ERROR STOP的擴展(Fortran 2036)Fortran 2036引入了ERROR STOP的擴展,允許傳遞錯誤代碼、錯誤消息和錯誤代碼的類型,并且可以指定錯誤代碼的類型。
program error_handling_example
implicit none
integer :: i
do i = 1, 10
if (i == 5) then
print *, "Error: i is 5, stopping execution."
error stop (error_code=1, error_message="Error code 1", error_type="Integer")
end if
print *, "i =", i
end do
end program error_handling_example
ERROR STOP和ERROR STOP的擴展(Fortran 2040)Fortran 2040引入了ERROR STOP的擴展,允許傳遞錯誤代碼、錯誤消息和錯誤代碼的類型,并且可以指定錯誤代碼的類型。
program error_handling_example
implicit none
integer :: i
do i = 1, 10
if (i == 5) then
print *, "Error: i is 5, stopping execution."
error stop (error_code=1, error_message="Error code 1", error_type="Integer")
end if
print *, "i =", i
end do
end program error_handling_example
ERROR STOP和ERROR STOP的擴展(Fortran 2044)Fortran 2044引入了ERROR STOP的擴展,允許傳遞錯誤代碼、錯誤消息和錯誤代碼的類型,并且可以指定錯誤代碼的類型。
program error_handling_example
implicit none
integer :: i
do i = 1, 10
if (i == 5) then
print *, "Error: i is 5, stopping execution."
error stop (error_code=1, error_message="Error code 1", error_type="Integer")
end if
print *, "i =", i
end do
end program error_handling_example
在Ubuntu下使用Fortran進行錯誤處理時,可以使用ERROR STOP語句及其擴展來終止程序并返回錯誤代碼。這些擴展允許傳遞錯誤消息和錯誤代碼的類型,從而提供更詳細的錯誤信息。