The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
lua_jailbreak_exception.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2011 - 2016 by Mark de Wever <[email protected]>
3  Part of the Battle for Wesnoth Project http://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 
16 
17 #include <cassert>
18 
20 
21 void tlua_jailbreak_exception::store() const throw()
22 {
23  /*
24  * It should not be possible to call this function with an exception still
25  * pending. It could happen if the code doesn't call
26  * tlua_jailbreak_exception::rethrow() or a logic error in the code.
27  */
28  assert(!jailbreak_exception);
29 
30  jailbreak_exception = this->clone();
31 }
32 
34 {
35  if(!jailbreak_exception) {
36  return;
37  }
38 
39  /*
40  * We need to call tlua_jailbreak_exception::clear() after the exception
41  * is thrown. The most straightforward approach would be a small helper
42  * class calling clear in its destructor, but alas g++ then complains about
43  * an unused variable. Since we're sure there will be something thrown use
44  * that fact to make sure the the function is called.
45  */
46  try {
48  } catch(...) {
49  clear();
50  throw;
51  }
52 
53  /* We never should reach this point. */
54  assert(false);
55 }
56 
58 {
59  delete jailbreak_exception;
60  jailbreak_exception = nullptr;
61 }
62 
void store() const
Stores a copy the current exception to be rethrown.
virtual tlua_jailbreak_exception * clone() const =0
Creates a copy of the current exception.
static void clear()
Clears the current exception.
static tlua_jailbreak_exception * jailbreak_exception
The exception to be rethrown.
static void rethrow()
Rethrows the stored exception.
Base class for exceptions that want to be thrown 'through' lua.
virtual void execute()=0
Executes the exception.