Skip to content

Commit

Permalink
Update the struct error to inherit from std::exception
Browse files Browse the repository at this point in the history
Signed-off-by: yamacir-kit <[email protected]>
  • Loading branch information
yamacir-kit committed Jun 1, 2024
1 parent e88007f commit 07abd19
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 25 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Procedures for each standard are provided by the following R7RS-style libraries:
cmake -B build -DCMAKE_BUILD_TYPE=Release
cd build
make package
sudo apt install build/meevax_0.5.188_amd64.deb
sudo apt install build/meevax_0.5.189_amd64.deb
```

or
Expand Down Expand Up @@ -122,9 +122,9 @@ sudo rm -rf /usr/local/share/meevax

| Target Name | Description
|-------------|-------------
| `all` | Build shared-library `libmeevax.0.5.188.so` and executable `meevax`
| `all` | Build shared-library `libmeevax.0.5.189.so` and executable `meevax`
| `test` | Test executable `meevax`
| `package` | Generate debian package `meevax_0.5.188_amd64.deb`
| `package` | Generate debian package `meevax_0.5.189_amd64.deb`
| `install` | Copy files into `/usr/local` directly

## Usage
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.5.188
0.5.189
8 changes: 4 additions & 4 deletions include/meevax/kernel/dynamic_environment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,14 +525,14 @@ inline namespace kernel
}();
}
}
catch (std::exception const& exception)
{
return reraise(make<error>(make<string>(exception.what())));
}
catch (error const& error)
{
return reraise(make(error));
}
catch (std::exception const& exception)
{
return reraise(make<error>(make<string>(exception.what())));
}
}
};
} // namespace kernel
Expand Down
8 changes: 6 additions & 2 deletions include/meevax/kernel/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace meevax
inline namespace kernel
{
struct error : public virtual pair // (<message> . <irritants>)
, public std::exception
{
struct detail
{
Expand All @@ -37,8 +38,12 @@ inline namespace kernel

std::vector<detail> details {};

mutable std::string brief {};

using pair::pair;

~error() override = default;

template <typename... Ts>
auto append(Ts&&... xs) -> auto &
{
Expand All @@ -59,8 +64,7 @@ inline namespace kernel

auto report(std::ostream &) const -> std::ostream &;

[[deprecated]]
auto what() const -> std::string;
auto what() const noexcept -> char const* override;
};

auto operator <<(std::ostream &, error const&) -> std::ostream &;
Expand Down
36 changes: 21 additions & 15 deletions src/kernel/error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,7 @@ inline namespace kernel

auto error::report(std::ostream & output) const -> std::ostream &
{
output << red("; error! ", static_cast<std::string>(message().as<string>()));

if (irritants())
{
output << red(": ", irritants());
}

output << std::endl;
output << red("; error! ", what()) << std::endl;

for (auto iter = details.rbegin(); iter != details.rend(); ++iter)
{
Expand All @@ -56,18 +49,31 @@ inline namespace kernel
return output;
}

auto error::what() const -> std::string
auto error::what() const noexcept -> char const*
{
std::stringstream ss {};
try
{
if (brief.empty())
{
auto output = std::stringstream();

ss << "error: " << static_cast<std::string>(message().as<string>());
output << static_cast<std::string>(message().as<string>());

if (irritants())
if (irritants())
{
output << ": " << irritants();
}

brief = output.str();
}

return brief.c_str();
}
catch (...)
{
ss << ": " << irritants();
std::cerr << "meevax::error::what failed to create an explanatory string for std::exception::what" << std::endl;
std::exit(EXIT_FAILURE);
}

return ss.str();
}

auto operator <<(std::ostream & os, error const& datum) -> std::ostream &
Expand Down

0 comments on commit 07abd19

Please sign in to comment.