Menu

Expect an exception — write exception-safe code

Unlike Windows API C code, OWLNext is C++ code, and you should expect that any function and constructor may throw an exception, unless it is explicitly stated in the API that it does not (i.e. the function signature has noexcept applied, or the now deprecated throw() specification). Unfortunately, as OWLNext is a thin wrapper for the Windows API, many programmers copy-and-paste code from the Windows documentation into their programs, code that is not written for exception safety. In particular, this becomes a big problem with functions that allocate resources, such as memory, GDI objects and file handles. Since an exception may occur, resources may leak, unless you carefully write your program to clean up, either by explicit exception handlers, or much more smartly, by using C++ code constructs, such as smart pointers, that exploit RAII to deallocate resources automatically.

Read more in our wiki article Exceptions and OWLNext.

Related

Wiki: Exceptions_and_OWLNext

Posted by Vidar Hasfjord 2018-03-16 Labels: Article Programming Advice

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.