Behavioral Attributes: nothrow and @nogc
Explore the behavioral attributes nothrow and @nogc in D programming. Understand how nothrow guarantees no exceptions escape a function and how @nogc restricts garbage collection usage. This lesson helps you write safer and more efficient D functions by mastering these attributes.
We'll cover the following...
nothrow functions
We discussed the exception mechanism in the exceptions chapter.
It would be good practice for functions to document the types of exceptions that they might throw under specific error conditions. However, as a general rule, callers should assume that any function can throw any exception.
Sometimes it is more important to know that a function does not emit any exception at all. For example, some algorithms can take advantage of the fact that certain steps cannot be interrupted by an exception.
nothrow guarantees that a function does not emit any exception: