Error handling

Generic errors and warnings

PARALLAX provides an error_handling_m module with a set of status codes to help manage errors and warnings in your code. This module allows you to gracefully handle errors, print informative warning messages, and terminate the program if necessary. Below is an example of how to use the error handling functionality:

! Error handling module
use error_handling_m, only : handle_error, error_info_t
! Error/warning status codes
use status_codes_m, only : PARALLAX_<ERR,WRN>_<CODE>
...
! Variables to be included in error messages
integer :: int1, int2, int3, ...
real(FP) :: fp1, fp2, fp3, ...

...

if (info /= 0) then ! Some error occurred
    call handle_error('Your error/warning message', PARALLAX_<ERR,WRN>_<CODE>, __LINE__, __FILE__, &
            additional_info=error_info_t('Further info:', &
                                        [int1, int2, int3], &  ! Integer variables
                                        [fp1, fp2, fp3]))      ! Real variables
endif

This will generate an error or warning message similar to the following:

  PARALLAX Error: code -6
  Your error/warning message
  Further info:           1           2           3   1.50000000000000        2.50000000000000        3.50000000000000     
  On line 647 in file test_diffusion.f90
  -1

PARALLAX writes via the preprocessor variables __LINE__ and __FILE__ the line number and filename of the source file, where the error occured. If the status code PARALLAX_<ERR,WRN>_<CODE> is a warning (positive value) then the code continues and just prints out information to screen. If it is an error code (negative value) the code is halted. additional_info can passed optionally to write out further information, like values of integer (int1,..) and real (fp1,...) variables. This can help diagnose the cause of the error more effectively.

NetCDF Error Handling

For error messages related to NetCDF I/O, a separate error handling routine is provided. It can be used as follows:

use error_handling_m, only : handle_error_netcdf
...
! Status returned by a NetCDF routine
integer :: nf90_stat

...

nf90_stat = nf90_<routine>
call handle_error_netcdf(nf90_stat, __LINE__, __FILE__)