ferror 1.4.1
FERROR is a library to assist with error handling in Fortran projects.
Loading...
Searching...
No Matches
ferror.f90
1! ferror.f90
2
84
85! ------------------------------------------------------------------------------
86
91module ferror
92 use, intrinsic :: iso_fortran_env, only : int32
93 implicit none
94 private
95 public :: errors
96 public :: error_callback
97
99 type :: errors
100 character(len = 256), private :: m_fname = "error_log.txt"
101 logical, private :: m_foundError = .false.
102 logical, private :: m_foundWarning = .false.
103 integer(int32), private :: m_errorFlag = 0
104 integer(int32), private :: m_warningFlag = 0
105 logical, private :: m_exitOnError = .true.
106 logical, private :: m_suppressPrinting = .false.
107 character(len = :), private, allocatable :: m_errorMessage
108 character(len = :), private, allocatable :: m_warningMessage
109 character(len = :), private, allocatable :: m_eFunName
110 character(len = :), private, allocatable :: m_wFunName
111 procedure(error_callback), private, pointer, pass :: m_errCleanUp => null()
112 contains
122 procedure, public :: get_log_filename => er_get_log_filename
123
133 procedure, public :: set_log_filename => er_set_log_filename
134
153 procedure, public :: report_error => er_report_error
154
171 procedure, public :: report_warning => er_report_warning
172
185 procedure, public :: log_error => er_log_error
186
196 procedure, public :: has_error_occurred => er_has_error_occurred
197
207 procedure, public :: reset_error_status => er_reset_error_status
208
218 procedure, public :: has_warning_occurred => er_has_warning_occurred
219
229 procedure, public :: reset_warning_status => er_reset_warning_status
230
240 procedure, public :: get_error_flag => er_get_error_flag
241
251 procedure, public :: get_warning_flag => er_get_warning_flag
252
264 procedure, public :: get_exit_on_error => er_get_exit_on_error
265
277 procedure, public :: set_exit_on_error => er_set_exit_on_error
278
290 procedure, public :: get_suppress_printing => er_get_suppress_printing
291
303 procedure, public :: set_suppress_printing => er_set_suppress_printing
304
314 procedure, public :: get_error_message => er_get_err_msg
315
325 procedure, public :: get_warning_message => er_get_warning_msg
326
336 procedure, public :: get_error_fcn_name => er_get_err_fcn
337
347 procedure, public :: get_warning_fcn_name => er_get_warning_fcn
348
358 procedure, public :: get_clean_up_routine => er_get_err_fcn_ptr
359
369 procedure, public :: set_clean_up_routine => er_set_err_fcn_ptr
370
371 end type
372
373 interface
374
376 subroutine error_callback(err, obj)
377 import errors
379 class(errors), intent(in) :: err
382 class(*), intent(inout) :: obj
383 end subroutine
384 end interface
385
386 ! ferror_implementation.f90
387 interface
388 pure module function er_get_log_filename(this) result(str)
389 class(errors), intent(in) :: this
390 character(len = :), allocatable :: str
391 end function
392
393 module subroutine er_set_log_filename(this, str)
394 class(errors), intent(inout) :: this
395 character(len = *), intent(in) :: str
396 integer(int32) :: n
397 end subroutine
398
399 module subroutine er_report_error(this, fcn, msg, flag, obj)
400 class(errors), intent(inout) :: this
401 character(len = *), intent(in) :: fcn, msg
402 integer(int32), intent(in) :: flag
403 class(*), intent(inout), optional :: obj
404 end subroutine
405
406 module subroutine er_report_warning(this, fcn, msg, flag)
407 class(errors), intent(inout) :: this
408 character(len = *), intent(in) :: fcn, msg
409 integer(int32), intent(in) :: flag
410 end subroutine
411
412 module subroutine er_log_error(this, fcn, msg, flag)
413 class(errors), intent(in) :: this
414 character(len = *), intent(in) :: fcn, msg
415 integer(int32), intent(in) :: flag
416 end subroutine
417
418 pure module function er_has_error_occurred(this) result(x)
419 class(errors), intent(in) :: this
420 logical :: x
421 end function
422
423 module subroutine er_reset_error_status(this)
424 class(errors), intent(inout) :: this
425 end subroutine
426
427 pure module function er_has_warning_occurred(this) result(x)
428 class(errors), intent(in) :: this
429 logical :: x
430 end function
431
432 module subroutine er_reset_warning_status(this)
433 class(errors), intent(inout) :: this
434 end subroutine
435
436 pure module function er_get_error_flag(this) result(x)
437 class(errors), intent(in) :: this
438 integer(int32) :: x
439 end function
440
441 pure module function er_get_warning_flag(this) result(x)
442 class(errors), intent(in) :: this
443 integer(int32) :: x
444 end function
445
446 pure module function er_get_exit_on_error(this) result(x)
447 class(errors), intent(in) :: this
448 logical :: x
449 end function
450
451 module subroutine er_set_exit_on_error(this, x)
452 class(errors), intent(inout) :: this
453 logical, intent(in) :: x
454 end subroutine
455
456 pure module function er_get_suppress_printing(this) result(x)
457 class(errors), intent(in) :: this
458 logical :: x
459 end function
460
461 module subroutine er_set_suppress_printing(this, x)
462 class(errors), intent(inout) :: this
463 logical, intent(in) :: x
464 end subroutine
465
466 module function er_get_err_msg(this) result(msg)
467 class(errors), intent(in) :: this
468 character(len = :), allocatable :: msg
469 integer(int32) :: n
470 end function
471
472 module function er_get_warning_msg(this) result(msg)
473 class(errors), intent(in) :: this
474 character(len = :), allocatable :: msg
475 integer(int32) :: n
476 end function
477
478 module function er_get_err_fcn(this) result(fcn)
479 class(errors), intent(in) :: this
480 character(len = :), allocatable :: fcn
481 integer(int32) :: n
482 end function
483
484 module function er_get_warning_fcn(this) result(fcn)
485 class(errors), intent(in) :: this
486 character(len = :), allocatable :: fcn
487 integer(int32) :: n
488 end function
489
490 module subroutine er_get_err_fcn_ptr(this, ptr)
491 class(errors), intent(in) :: this
492 procedure(error_callback), intent(out), pointer :: ptr
493 end subroutine
494
495 module subroutine er_set_err_fcn_ptr(this, ptr)
496 class(errors), intent(inout) :: this
497 procedure(error_callback), intent(in), pointer :: ptr
498 end subroutine
499 end interface
500
501! ------------------------------------------------------------------------------
502end module
bool get_exit_on_error(const error_handler *err)
Gets a logical value determining if the application should be terminated when an error is encountered...
int get_error_flag(const error_handler *err)
Gets the current error flag.
void set_log_filename(error_handler *err, const char *fname)
Sets the error log filename.
bool has_warning_occurred(const error_handler *err)
Tests to see if a warning has been encountered.
void report_warning(error_handler *err, const char *fcn, const char *msg, int flag)
Reports a warning condition to the user.
void reset_warning_status(error_handler *err)
Resets the warning status flag to false, and the current warning flag to zero.
void reset_error_status(error_handler *err)
Resets the error status flag to false, and the current error flag to zero.
bool has_error_occurred(const error_handler *err)
Tests to see if an error has been encountered.
void set_suppress_printing(error_handler *err, bool x)
Sets a logical value determining if printing of error and warning messages should be suppressed.
void log_error(const error_handler *err, const char *fcn, const char *msg, int flag)
Writes an error log file.
void report_error(error_handler *err, const char *fcn, const char *msg, int flag)
Reports an error condition to the user.
void get_warning_fcn_name(const error_handler *err, char *fname, int *nfname)
Gets the name of the function or subroutine that issued the last warning message.
void get_log_filename(const error_handler *err, char *fname, int *nfname)
Gets the name of the error log file.
void get_error_message(const error_handler *err, char *msg, int *nmsg)
Gets the current error message.
int get_warning_flag(const error_handler *err)
Gets the current warning flag.
void get_error_fcn_name(const error_handler *err, char *fname, int *nfname)
Gets the name of the function or subroutine that issued the last error message.
void get_warning_message(const error_handler *err, char *msg, int *nmsg)
Gets the current warning message.
void set_exit_on_error(error_handler *err, bool x)
Sets a logical value determining if the application should be terminated when an error is encountered...
bool get_suppress_printing(const error_handler *err)
Gets a logical value determining if printing of error and warning messages should be suppressed.
Defines the signature of a routine that can be used to clean up after an error condition is encounter...
Definition: ferror.f90:376
ferror
Definition: ferror.f90:91
Defines a type for managing errors and warnings.
Definition: ferror.f90:99