mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-16 08:27:31 +08:00
doc: write about source_location in exceptions
This commit is contained in:
34
README.md
34
README.md
@@ -68,6 +68,8 @@ int main()
|
||||
- [TOML literal](#toml-literal)
|
||||
- [Conversion between toml value and arbitrary types](#conversion-between-toml-value-and-arbitrary-types)
|
||||
- [Formatting user-defined error messages](#formatting-user-defined-error-messages)
|
||||
- [Obtaining location information](#obtaining-location-information)
|
||||
- [Exceptions](#exceptions)
|
||||
- [Serializing TOML data](#serializing-toml-data)
|
||||
- [Underlying types](#underlying-types)
|
||||
- [Unreleased TOML features](#unreleased-toml-features)
|
||||
@@ -351,6 +353,7 @@ The above code works with the following toml file.
|
||||
# NOT {"physical": {"color": "orange"}}.
|
||||
```
|
||||
|
||||
|
||||
## Casting a toml value
|
||||
|
||||
### `toml::get`
|
||||
@@ -1258,7 +1261,7 @@ you will get an error message like this.
|
||||
| ~~ maximum number here
|
||||
```
|
||||
|
||||
### Obtaining location information
|
||||
## Obtaining location information
|
||||
|
||||
You can also format error messages in your own way by using `source_location`.
|
||||
|
||||
@@ -1283,6 +1286,35 @@ const toml::value v = /*...*/;
|
||||
const toml::source_location loc = v.location();
|
||||
```
|
||||
|
||||
## Exceptions
|
||||
|
||||
All the exceptions thrown by toml11 inherits `toml::exception` that inherits
|
||||
`std::exception`.
|
||||
|
||||
```cpp
|
||||
namespace toml {
|
||||
struct exception : public std::exception {/**/};
|
||||
struct syntax_error : public toml::exception {/**/};
|
||||
struct type_error : public toml::exception {/**/};
|
||||
struct internal_error : public toml::exception {/**/};
|
||||
} // toml
|
||||
```
|
||||
|
||||
`toml::exception` has `toml::exception::location()` member function that returns
|
||||
`toml::source_location`, in addition to `what()`.
|
||||
|
||||
```cpp
|
||||
namespace toml {
|
||||
struct exception : public std::exception
|
||||
{
|
||||
// ...
|
||||
source_location const& location() const noexcept;
|
||||
};
|
||||
} // toml
|
||||
```
|
||||
|
||||
It represents where the error occurs.
|
||||
|
||||
## Serializing TOML data
|
||||
|
||||
toml11 enables you to serialize data into toml format.
|
||||
|
Reference in New Issue
Block a user