Archive for the ‘mechanisms’ Category
Exceptional initialization list
Posted 30/11/2010
on:- In: mechanisms
- 9 Comments
Using the initialization list is very much encouraged in C++, and rightfully so – it has many benefits. But what happens if one of your members fails at initialization and actually throws an exception? Even worse: what happens if that member’s constructor throws an exception not in your exception specification list?
Thunksgiving
Posted 31/10/2010
on:Quoting Wikipedia:
The word thunk has at least three related meanings in computing science. A “thunk” may be:
- A piece of code to perform a delayed computation (similar to a closure)
- A feature of some virtual function table implementations (similar to a wrapper function)
- A mapping of machine data from one system-specific form to another, usually for compatibility reasons
In all three senses, the word refers to a piece of low-level code, usually machine-generated, that implements some detail of a particular software system.
In this post (whose name looks like an unrelated typo) we shall observe the need for a thunk of the second kind, in C++.
- In: mechanisms
- 2 Comments
The handler std::terminate() is called whenever the exception handling mechanism cannot find a suitable catch clause for a thrown exception (and in some other cases. For example, when an exception is thrown during the handling of another exception – see this GotW post about std::uncaught_exception). It is possible to define a custom handler by using std::set_terminate.
In this post we would like to create a terminate handler which will be able to catch the exception that led to its invocation, when there is one.
Template template parameters
Posted 19/10/2009
on:This is actually not a typo, I really meant to repeat the first word. Let’s see what template template parameters are..
Exception specifications
Posted 06/10/2009
on:- In: mechanisms
- 9 Comments
C++ provides a mechanism that allows any function to declare exactly which exception types it may throw, and these declerations are actually enforced in runtime. We will review exactly how this mechanism works, and why it is usually left unused.
- In: mechanisms
- 5 Comments
This post continues and explains the previous erroneous post.
In the example from the previous post, our base class has invoked a virtual function during the construction of the object, expecting that the correct function would be called. Why was that an error, you ask ?
Read the rest of this entry »
Everything about namespaces
Posted 24/09/2009
on:I’ll assume you are already familiar with the concept of namespaces, and the using keyword. So let me try and introduce some of the less common features of the namespace mechanism.
Recent comments