O'Reilly logo

Boost.Asio C++ Network Programming - Second Edition by John Torjo, Wisnu Anggoro

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Handling exceptions and errors

Sometimes, our code will throw an exception or error at runtime. As you may remember in our discussion of the lexical.cpp in Chapter 3, Introducing the Boost C++ Libraries, we must sometimes use exception handling in our code, and we will now dig it up to delve into exception and error handling.

Handling an exception

An exception is a way of reacting to a situation in which the code has exceptional circumstances by transferring control to the handler. To handle the exception, we need to use the try-catch block in our code; then, if an exceptional circumstance arises, an exception will be thrown to the exception handler.

Now, take a look at the following code to see how exception handling is used:

/* exception.cpp */ ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required