Map as member variable throwing read access violation on insert


So I've been having this weird issue, I have maps as member variables in a class, but when I go to insert the first element in the map, I get a Exception has occurred: W32/0xc0000005 Unhandled exception thrown: read access violation. _Scary was nullptr. error. I've got the relevant code below, please help.

Edit: No exception is actually thrown at runtime, or at least it's not caught in the catch block. I have to go into debug mode to read the exception, any idea why that is?


try {
auto server = std::make_shared<express::Server>(8080);
          [](express::request req, express::response res) {
            std::string message =
                "<html><title>Hello World!</title></html>";
    .get("/file", [](express::request req, express::response res) {

server->listen("", "/");

} catch (const std::exception& e) {
     std::cerr << e.what() << std::endl;
    return EXIT_FAILURE;
class Server : public std::enable_shared_from_this<Server> {
  Server(unsigned short port);

  void acceptConnection();

  void listen(std::string address, std::string doc_root);

  // Can throw runtime exceptions
  Server& get(const std::string& path, reqHandler callback);

  boost::asio::io_context m_ioc{MAX_THREADS};
  tcp::acceptor m_acceptor;
  unsigned short m_port;
  std::string m_docRoot;
  std::shared_ptr<requestHandler> m_handler;

  //   {urlPath, lambda}
Server& Server::get(const std::string& path, reqHandler callback) {
  m_handler->addPath(verb::GET, path, callback);
  return *this;
class requestHandler {
  std::map<const std::string, reqHandler> m_get;

  requestHandler() = default;

  reqHandler getHandler(verbs verb, const std::string& path);
  void addPath(verbs verb, const std::string& path, reqHandler callback);
  void addAll(std::string& path, reqHandler callback);
void requestHandler::addPath(verbs verb, const std::string& path,
                             reqHandler callback) {
  switch (verb) {
    case verbs::GET:
      m_get.insert({path, callback});
asked on Stack Overflow Jun 18, 2020 by Kenny Castro • edited Jun 18, 2020 by Kenny Castro

0 Answers

Nobody has answered this question yet.

User contributions licensed under CC BY-SA 3.0