File: stdlib_error.md

package info (click to toggle)
fortran-stdlib 0.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 34,008 kB
  • sloc: f90: 24,178; ansic: 1,244; cpp: 623; python: 119; makefile: 13
file content (104 lines) | stat: -rw-r--r-- 2,178 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
---
title: error
---

# The `stdlib_error` module

[TOC]

## Introduction

Catching and handling errors.

## Procedures and methods provided


### `check` - Checks the value of a logical condition

#### Status

Experimental

#### Description

Checks the value of a logical condition.

#### Syntax

`call ` [[check(subroutine)]] `(condition, msg, code, warn)`


#### Arguments

`condition`: Shall be a scalar of type `logical`.

`msg` (optional): Shall be a character expression containing the message to be printed to `stderr`. The default `msg` is 'Check failed.'.

`code` (optional): Shall be a scalar of type `integer`. The default `code` is `1`.

`warn` (optional): Shall be a scalar of type `logical`. The default `warn` is `.true.`.

#### Return value

If `condition` is `.false.`, and:

 * no other arguments are provided, this subroutine stops the program with the default message and exit code 1;

 * `msg` is provided, this subroutine stops the program and it prints the value of `msg`;

 * `code` is provided, this subroutine stops the program with the given exit code;

 * `warn` is provided and `warn` is `.true.`, this subroutine doesn't stop the program and prints the message.

#### Examples

```fortran
{!example/error/example_check1.f90!}
```
```fortran
{!example/error/example_check2.f90!}
```
```fortran
{!example/error/example_check3.f90!}
```
```fortran
{!example/error/example_check4.f90!}
```

### `error_stop` - aborts the program

#### Status

Experimental

#### Description

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

#### Syntax

`call ` [[stdlib_error(module):error_stop(interface)]] `(msg, code)`

#### Arguments

`msg`: Shall be a character expression containing the message to be printed to `stderr`.

`code` (optional): Shall be a scalar of type `integer` to be returned as exit code.

#### Output

Aborts the program with printing the message `msg` to `stderr` and a nonzero exit code. The nonzero exit code is equal to `code` if provided, and 1 otherwise.

#### Examples

Without error code:

```fortran
{!example/error/example_error_stop1.f90!}
```

With error code:

```fortran
{!example/error/example_error_stop2.f90!}
```