Skip to content

Commit

Permalink
Remove std::stringstream usage in error-utils.h
Browse files Browse the repository at this point in the history
  • Loading branch information
rafalh committed Sep 22, 2024
1 parent 96ca8f6 commit 7c99bf1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
20 changes: 12 additions & 8 deletions common/include/common/error/error-utils.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#include <windows.h>
#include <ostream>
#include <sstream>
#include <string>
#include <exception>

inline std::string get_win32_error_description(DWORD error)
{
Expand All @@ -29,19 +29,23 @@ inline std::string get_win32_error_description(DWORD error)
return message;
}

inline void print_exception(const std::exception& e, std::ostream& stream, int level = 0)
inline void print_exception(const std::exception& e, std::string& buf, int level = 0)
{
stream << std::string(level, ' ') << e.what() << '\n';
for (int i = 0; i < level; ++i) {
buf += ' ';
}
buf += e.what();
buf += '\n';
try {
std::rethrow_if_nested(e);
} catch(const std::exception& e) {
print_exception(e, stream, level + 1);
print_exception(e, buf, level + 1);
} catch(...) {}
}

inline std::string generate_message_for_exception(const std::exception& e)
{
std::stringstream ss;
print_exception(e, ss);
return ss.str();
std::string buf;
print_exception(e, buf);
return buf;
}
1 change: 0 additions & 1 deletion game_patch/os/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#pragma once

#include <patch_common/Traits.h>
#include <functional>
#include <optional>
#include "../rf/os/console.h"
#include "../rf/localize.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include <vector>
#include <memory>
#include <cstdlib>
#include <cstddef>
#include <cstring>
#include <patch_common/MemUtils.h>
Expand Down

0 comments on commit 7c99bf1

Please sign in to comment.