From 2bc97e90ad5d59581ef8da3174946a7e427ccbcb Mon Sep 17 00:00:00 2001
From: Brigitt Bright <brigittbright@Brigitts-MacBook-Air.local>
Date: Mon, 24 Aug 2020 21:16:30 +0200
Subject: [PATCH] Fixed issue #19. Added a try-catch-phrase to handle thrown
 exceptions

---
 server_http.hpp | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/server_http.hpp b/server_http.hpp
index c6402f5..f5dc520 100644
--- a/server_http.hpp
+++ b/server_http.hpp
@@ -762,10 +762,20 @@ namespace SimpleWeb {
                 return;
               }
             }
-            if(std::stof(response->session->request->http_version) >= 1.1) {
-              auto new_session = std::make_shared<Session>(this->config.max_request_streambuf_size, response->session->connection);
-              this->read(new_session);
-              return;
+            try {
+              if(std::stof(response->session->request->http_version) >= 1.1) {
+                auto new_session = std::make_shared<Session>(this->config.max_request_streambuf_size, response->session->connection);
+                this->read(new_session);
+                return;
+              }
+            }
+            catch(const std::invalid_argument &exception) {
+              std::cerr << "Invalid argument: "
+                        << "HTTP-version is not valid" << '\n';
+            }
+            catch(const std::out_of_range &exception) {
+              std::cerr << "Invalid argument: "
+                        << "HTTP-version is out of range; too large" << '\n';
             }
           }
           else if(this->on_error)
-- 
GitLab