cplusplus.co.il

Archive for the ‘mechanisms’ Category

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?

Read the rest of this entry »

Thunksgiving

Posted on: 31/10/2010

Quoting Wikipedia:

The word thunk has at least three related meanings in computing science. A “thunk” may be:

  1. A piece of code to perform a delayed computation (similar to a closure)
  2. A feature of some virtual function table implementations (similar to a wrapper function)
  3. 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++.

Read the rest of this entry »

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.

Read the rest of this entry »

This is actually not a typo, I really meant to repeat the first word. Let’s see what template template parameters are..

Read the rest of this entry »

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.

Read the rest of this entry »

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 »

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.

Read the rest of this entry »


Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 27 other subscribers

Categories