mirror of
https://github.com/ToruNiina/toml11.git
synced 2024-11-22 20:30:11 +00:00
doc: add example of hints in an error message
This commit is contained in:
parent
fecd50dfeb
commit
f31dc6ba37
21
README.md
21
README.md
@ -1300,6 +1300,27 @@ you will get an error message like this.
|
||||
| ~~ maximum number here
|
||||
```
|
||||
|
||||
You can print hints at the end of the message.
|
||||
|
||||
```cpp
|
||||
std::vector<std::string> hints;
|
||||
hints.push_back("positive number means n >= 0.");
|
||||
hints.push_back("negative number is not positive.");
|
||||
std::cerr << toml::format_error("[error] value should be positive",
|
||||
data.at("num"), "positive number required", hints)
|
||||
<< std::endl;
|
||||
```
|
||||
|
||||
```console
|
||||
[error] value should be positive
|
||||
--> example.toml
|
||||
2 | num = 42
|
||||
| ~~ positive number required
|
||||
|
|
||||
Hint: positive number means n >= 0.
|
||||
Hint: negative number is not positive.
|
||||
```
|
||||
|
||||
## Obtaining location information
|
||||
|
||||
You can also format error messages in your own way by using `source_location`.
|
||||
|
Loading…
Reference in New Issue
Block a user