Skip to content

Commit 24f6b3e

Browse files
committed
Improve experimental_error doc & link w/ spec
This commit improves the inline FORD documentation of experimental_error and provides some examples of how to use the FORD linking syntax in the spec.
1 parent 18f4845 commit 24f6b3e

File tree

2 files changed

+48
-29
lines changed

2 files changed

+48
-29
lines changed

doc/specs/stdlib_experimental_error.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@ title: experimental_error
66

77
[TOC]
88

9-
## `check` - Checks the value of a logical condition
9+
## `[[stdlib_experimental_error(module):check(subroutine)]]` - Checks the value of a logical condition
1010

1111
### Description
1212

1313
Checks the value of a logical condition.
1414

1515
### Syntax
1616

17-
`call check(condition, msg, code, warn)`
17+
`call [[check(subroutine)]](condition, msg, code, warn)`
18+
1819

1920
### Arguments
2021

@@ -77,15 +78,15 @@ program demo_check3
7778
end program demo_check3
7879
```
7980

80-
## `error_stop` - aborts the program
81+
## `[[stdlib_experimental_error:error_stop]]` - aborts the program
8182

8283
### Description
8384

8485
Aborts the program with a message and a nonzero exit code.
8586

8687
### Syntax
8788

88-
`call error_stop(msg, code)`
89+
`call [[stdlib_experimental_error(module):error_stop(interface)]](msg, code)`
8990

9091
### Arguments
9192

src/stdlib_experimental_error.f90

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
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).__
35
use, intrinsic :: iso_fortran_env, only: stderr => error_unit
46
use stdlib_experimental_optval, only: optval
57
implicit none
68
private
79

810
interface ! f{08,18}estop.f90
911
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).__
1015
character(*), intent(in) :: msg
1116
integer, intent(in), optional :: code
1217
end subroutine error_stop
@@ -17,15 +22,44 @@ end subroutine error_stop
1722
contains
1823

1924
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+
!!```
2062

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.
2963
!
3064
! Arguments
3165
! ---------
@@ -36,22 +70,6 @@ subroutine check(condition, msg, code, warn)
3670
logical, intent(in), optional :: warn
3771
character(*), parameter :: msg_default = 'Check failed.'
3872

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-
5573
if (.not. condition) then
5674
if (optval(warn, .false.)) then
5775
write(stderr,*) optval(msg, msg_default)

0 commit comments

Comments
 (0)