Let twml_exception no longer derive from a base.

This how I originally designed the class and how it should behave. This

reverts 2011-01-26T07:30:35Z!guillaume.melquiond@gmail.com and reintroduces bug #17577. There are two
issues when used in combination with Lua:

 - Our Lua wrapper crashes when catching this exception (to be fixed in my next
   commit.)

 - When our Lua wrapper no longer crashes the error message is lost. (I have an
   idea how to fix it, but it is much easier to test when this change is
   committed.)
This commit is contained in:
Mark de Wever 2011-02-16 18:59:46 +00:00
parent 74463ee619
commit ec0eb48ead
5 changed files with 18 additions and 8 deletions

View file

@ -61,7 +61,7 @@ editor_map editor_map::from_string(const config& terrain_cfg, const std::string&
} catch (incorrect_map_format_error& e) {
throw wrap_exc("format", e.message, "");
} catch (twml_exception& e) {
throw wrap_exc("wml", e.message, "");
throw wrap_exc("wml", e.user_message, "");
} catch (config::error& e) {
throw wrap_exc("config", e.message, "");
}

View file

@ -2483,7 +2483,7 @@ int main(int argc, char** argv)
std::cerr << "caught end_level_exception (quitting)\n";
} catch(twml_exception& e) {
std::cerr << "WML exception:\nUser message: "
<< e.message << "\nDev message: " << e.dev_message << '\n';
<< e.user_message << "\nDev message: " << e.dev_message << '\n';
return 1;
} catch(game_logic::formula_error& e) {
std::cerr << e.what()

View file

@ -199,7 +199,7 @@ BOOST_AUTO_TEST_CASE(test_make_test_fake)
gui2::tmessage dlg("title", "message", true);
dlg.show(video, 1);
} catch(twml_exception& e) {
BOOST_CHECK(e.message == _("Failed to show a dialog, "
BOOST_CHECK(e.user_message == _("Failed to show a dialog, "
"which doesn't fit on the screen."));
return;
} catch(...) {

View file

@ -58,7 +58,7 @@ void twml_exception::show(display &disp)
// The extra spaces between the \n are needed, otherwise the dialog doesn't show
// an empty line.
sstr << _("An error due to possibly invalid WML occurred\nThe error message is :")
<< "\n" << message << "\n \n"
<< "\n" << user_message << "\n \n"
<< _("When reporting the bug please include the following error message :")
<< "\n" << dev_message;

View file

@ -23,7 +23,8 @@
#define WML_EXCEPTION_HPP_INCLUDED
#include "config.hpp"
#include "exceptions.hpp"
#include <string>
class display;
@ -82,13 +83,22 @@ void wml_exception(
, const std::string& dev_message = "");
/** Helper class, don't construct this directly. */
struct twml_exception: game::error
struct twml_exception
{
twml_exception(const std::string &user_msg, const std::string &dev_msg)
: game::error(user_msg), dev_message(dev_msg) {}
twml_exception(const std::string& user_msg, const std::string& dev_msg)
: user_message(user_msg)
, dev_message(dev_msg)
{
}
~twml_exception() throw() {}
/**
* The message for the user explaining what went wrong. This message can
* be translated so the user gets a explanation in his/her native tongue.
*/
std::string user_message;
/**
* The message for developers telling which problem was triggered, this
* shouldn't be translated. It's hard for a dev to parse errors in