The Battle for Wesnoth  1.19.5+dev
general.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2024
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #include "utils/general.hpp"
16 
17 #if defined(__clang__) || defined(__GNUG__)
18 #include <cxxabi.h>
19 #endif
20 
21 namespace utils
22 {
24 {
25 #if defined(__clang__) || defined(__GNUG__)
26  std::string to_demangle = __cxxabiv1::__cxa_current_exception_type()->name();
27  int status = 0;
28  char* buff = __cxxabiv1::__cxa_demangle(to_demangle.c_str(), NULL, NULL, &status);
29  if(status == 0)
30  {
31  std::string demangled = buff;
32  std::free(buff);
33  return demangled;
34  }
35  else
36  {
37  return to_demangle;
38  }
39 #else
40  return "";
41 #endif
42 }
43 }
std::string get_unknown_exception_type()
Utility function for finding the type of thing caught with catch(...).
Definition: general.cpp:23