Changes between Version 5 and Version 6 of code/Error_handling
- Timestamp:
- Apr 12, 2017, 10:15:42 PM (8 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
code/Error_handling
v5 v6 1 1 = Error handling in Orxonox = 2 [[TracNav(TracNav/TOC_Development)]]3 2 4 3 Whenever something unwanted happens, the programmer needs to react in a certain way.[[br]] … … 10 9 11 10 == orxout(#), displays messages == 12 Whenever you want to show the user or the programmer a message, use orxout(#) where # is the level of your output. See [wiki: Output] for more information. [[br]]11 Whenever you want to show the user or the programmer a message, use orxout(#) where # is the level of your output. See [wiki:doc/Output] for more information. [[br]] 13 12 14 13 '''Note: A simple message with level user_error (or internal_error) doesn't trigger an exception or anything yet''' … … 16 15 == Exceptions == 17 16 This kind of error handling method is used when the programmer has to handle situations that could go wrong, but shouldn't. Mind the difference to Assertions below! [[br]] 18 For information about how to use them, see [wiki: Exception Exceptions]. [[br]]17 For information about how to use them, see [wiki:doc/Exception Exceptions]. [[br]] 19 18 A good example for exceptions would be a script compiler. Whenever it encounters bad tokens, it throws an exception with a message. The function calling the parser can then catch that exception, display it and act accordingly. [[br]] 20 19 We also use Exceptions when loading a level. If one occurs, we can abort and the user can choose another level. Of course this shouldn't happen, but nobody's perfect. [[br]][[br]] … … 39 38 '''Important: Asserts are only useful when the mistake is in the program. Throwing asserts for bad input doesn't help anyone, use exceptions then! [[br]] 40 39 41 Usage: 'assert(condition you assume);' or when you want to tell more use ' OrxAssert(condition, message)'. The message gets then displayed via orxout(user_error) before the assert() macro is called. [[br]]40 Usage: 'assert(condition you assume);' or when you want to tell more use '!OrxAssert(condition, message)'. The message gets then displayed via orxout(user_error) before the assert() macro is called. [[br]] 42 41 The example above would then read: 43 42