      program example33b
      include 'mpif.h'
      COMMON/vars/ errors, calls
      integer errors, calls, errhandler
      external err_function
      errors=0
      calls=0
      call MPI_INIT(ierr)
      call MPI_COMM_CREATE_ERRHANDLER(err_function, errhandler,
     &                                ierr)
      call MPI_COMM_SET_ERRHANDLER(MPI_COMM_WORLD, errhandler,
     &                             ierr)
      call MPI_COMM_CALL_ERRHANDLER(MPI_COMM_WORLD,
     &                              MPI_ERR_OTHER, ierr)
      call MPI_ERRHANDLER_FREE(errhandler, ierr)
      print *, "Error handler was called", calls, 
     &         " times, with", errors, " errors"
      call MPI_FINALIZE(ierr)
      end
      subroutine err_function(comm, err)
      integer comm, err
      include 'mpif.h'
      COMMON/vars/ errors, calls
      integer errors, calls
      if(err .eq. MPI_ERR_OTHER) then
         print *, "Error MPI_ERR_OTHER"
      else
         errors=errors+1
         print *, "Error code ", err
      end if
      calls=calls+1
      end
