1
1
module stdlib_experimental_error
2
- ! !Provides a support for catching and handling errors
2
+ ! ! Provide support for catching and handling errors ([spec](../page/specs/stdlib_experimental_error.html))
3
+ ! !
4
+ ! ! __Read the [specification here](../page/specs/stdlib_experimental_error.html).__
3
5
use , intrinsic :: iso_fortran_env, only: stderr = > error_unit
4
6
use stdlib_experimental_optval, only: optval
5
7
implicit none
6
8
private
7
9
8
10
interface ! f{08,18}estop.f90
9
11
module subroutine error_stop (msg , code )
12
+ ! ! Provides a call to `error stop` and allows the user to specify a code and message.
13
+ ! !
14
+ ! ! __Read the [specification here](..//page/specs/stdlib_experimental_error.html#description_1).__
10
15
character (* ), intent (in ) :: msg
11
16
integer , intent (in ), optional :: code
12
17
end subroutine error_stop
@@ -17,15 +22,44 @@ end subroutine error_stop
17
22
contains
18
23
19
24
subroutine check (condition , msg , code , warn )
25
+ ! ! Checks the value of a logical condition. ([spec](../page/specs/stdlib_experimental_error.html#description))
26
+ ! !
27
+ ! ! __Read the [specification here](../page/specs/stdlib_experimental_error.html#description).__
28
+ ! !
29
+ ! !##### Behavior
30
+ ! !
31
+ ! ! If `condition == .false.` and:
32
+ ! !
33
+ ! ! * No other arguments are provided, it stops the program with the default
34
+ ! ! message and exit code `1`;
35
+ ! ! * `msg` is provided, it prints the value of `msg`;
36
+ ! ! * `code` is provided, it stops the program with the given exit code;
37
+ ! ! * `warn` is provided and `.true.`, it doesn't stop the program and prints
38
+ ! ! the message.
39
+ ! !
40
+ ! !##### Examples
41
+ ! !
42
+ ! !* If `a /= 5`, stops the program with exit code `1`
43
+ ! ! and prints `Check failed.`
44
+ ! !``` fortran
45
+ ! ! call check(a == 5)
46
+ ! !```
47
+ ! !
48
+ ! !* As above, but prints `a == 5 failed`.
49
+ ! !``` fortran
50
+ ! ! call check(a == 5, msg='a == 5 failed.')
51
+ ! !```
52
+ ! !
53
+ ! !* As above, but doesn't stop the program.
54
+ ! !``` fortran
55
+ ! ! call check(a == 5, msg='a == 5 failed.', warn=.true.)
56
+ ! !```
57
+ ! !
58
+ ! !* As example #2, but stops the program with exit code `77`
59
+ ! !``` fortran
60
+ ! ! call check(a == 5, msg='a == 5 failed.', code=77)
61
+ ! !```
20
62
21
- ! Checks the value of a logical condition. If condition == .false. and:
22
- !
23
- ! * No other arguments are provided, it stops the program with the default
24
- ! message and exit code 1;
25
- ! * msg is provided, it prints the value of msg;
26
- ! * code is provided, it stops the program with the given exit code;
27
- ! * warn is provided and .true., it doesn't stop the program and prints
28
- ! * the message.
29
63
!
30
64
! Arguments
31
65
! ---------
@@ -36,22 +70,6 @@ subroutine check(condition, msg, code, warn)
36
70
logical , intent (in ), optional :: warn
37
71
character (* ), parameter :: msg_default = ' Check failed.'
38
72
39
- ! Examples
40
- ! --------
41
- !
42
- ! ! If a /= 5, stops the program with exit code 1
43
- ! ! and prints 'Check failed.'
44
- ! call check(a == 5)
45
- !
46
- ! ! As above, but prints 'a == 5 failed.'
47
- ! call check(a == 5, msg='a == 5 failed.')
48
- !
49
- ! ! As above, but doesn't stop the program.
50
- ! call check(a == 5, msg='a == 5 failed.', warn=.true.)
51
- !
52
- ! ! As example #2, but stops the program with exit code 77
53
- ! call check(a == 5, msg='a == 5 failed.', code=77)
54
-
55
73
if (.not. condition) then
56
74
if (optval(warn, .false. )) then
57
75
write (stderr,* ) optval(msg, msg_default)
0 commit comments