PolyVox  0.3.0-dev
Open source voxel management library
ErrorHandling.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2 Copyright (c) 2005-2009 David Williams
3 
4 This software is provided 'as-is', without any express or implied
5 warranty. In no event will the authors be held liable for any damages
6 arising from the use of this software.
7 
8 Permission is granted to anyone to use this software for any purpose,
9 including commercial applications, and to alter it and redistribute it
10 freely, subject to the following restrictions:
11 
12  1. The origin of this software must not be misrepresented; you must not
13  claim that you wrote the original software. If you use this software
14  in a product, an acknowledgment in the product documentation would be
15  appreciated but is not required.
16 
17  2. Altered source versions must be plainly marked as such, and must not be
18  misrepresented as being the original software.
19 
20  3. This notice may not be removed or altered from any source
21  distribution.
22 *******************************************************************************/
23 
25 
26 #ifndef POLYVOX_THROW_ENABLED
27  namespace PolyVox
28  {
29  void defaultThrowHandler(std::exception& e, const char* file, int line)
30  {
31  std::cerr << std::endl << std::endl; \
32  std::cerr << " PolyVox exception thrown!" << std::endl; \
33  std::cerr << " =========================" << std::endl; \
34  std::cerr << " PolyVox has tried to throw an exception but it was built without support" << std::endl; \
35  std::cerr << " for exceptions. In this scenario PolyVox will call a 'throw handler'" << std::endl; \
36  std::cerr << " and this message is being printed by the default throw handler." << std::endl << std::endl; \
37 
38  std::cerr << " If you don't want to enable exceptions then you should try to determine why" << std::endl; \
39  std::cerr << " this exception was thrown and make sure it doesn't happen again. If it was" << std::endl; \
40  std::cerr << " due to something like an invalid argument to a function then you should be" << std::endl; \
41  std::cerr << " able to fix it quite easily by validating parameters as appropriate. More" << std::endl; \
42  std::cerr << " complex exception scenarios (out of memory, etc) might be harder to fix and" << std::endl; \
43  std::cerr << " you should replace this default handler with something which is more" << std::endl; \
44  std::cerr << " meaningful to your users." << std::endl << std::endl; \
45 
46  std::cerr << " Exception details" << std::endl; \
47  std::cerr << " -----------------" << std::endl; \
48  std::cerr << " Line: " << line << std::endl; \
49  std::cerr << " File: " << file << std::endl; \
50  std::cerr << " Message: " << e.what() << std::endl << std::endl; \
51 
52  POLYVOX_HALT(); \
53  }
54 
56  {
57  static ThrowHandler s_fThrowHandler = &defaultThrowHandler;
58  return s_fThrowHandler;
59  }
60 
62  {
63  return getThrowHandlerInstance();
64  }
65 
66  void setThrowHandler(ThrowHandler fNewHandler)
67  {
68  getThrowHandlerInstance() = fNewHandler;
69  }
70  }
71 #endif