---
title: llarp/win32/exception.hpp

---

# llarp/win32/exception.hpp



## Namespaces

| Name           |
| -------------- |
| **[llarp](Namespaces/namespacellarp.md)** <br>[crypto.hpp] |
| **[llarp::win32](Namespaces/namespacellarp_1_1win32.md)**  |

## Classes

|                | Name           |
| -------------- | -------------- |
| class | **[llarp::win32::error](Classes/classllarp_1_1win32_1_1error.md)**  |




## Source code

```cpp
#pragma once

#include <array>
#include <string>
#include <windows.h>
#include <stdexcept>

#include <llarp/util/str.hpp>

namespace llarp::win32
{
  namespace
  {
    inline std::string
    error_to_string(DWORD err)
    {
      std::array<CHAR, 512> buffer{};

      FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, &err, 0, 0, buffer.data(), buffer.size(), nullptr);
      return std::string{buffer.data()};
    }
  }  // namespace

  class error : public std::runtime_error
  {
   public:
    error(DWORD err, std::string msg)
        : std::runtime_error{fmt::format("{}: {}", msg, error_to_string(err))}
    {}
  };
}  // namespace llarp::win32
```


-------------------------------

Updated on 2022-08-30 at 18:09:28 +0000
