Posts Tagged exception

Searching for a Non-Nullable Reference Type

Tags: , , ,

The inventor of null references has called them his billion dollar mistake. We’ve all felt that pain so many times. After a while it can seem like null references are inevitable. They’re just a built-in sharp edge we have to carefully avoid cutting ourselves on. But is this true? Is there some way we can avoid the possibility of a null reference in the first place? Today we’ll go searching for such a mythical type.

Read the rest of this article »

8 Comments

C++ For C# Developers: Part 52 – Idioms and Best Practices

Tags: , , , , , , , ,

As a very large language used for a very wide range of purposes over many decades, C++ can be written in a lot of different ways. Today we’ll look at some of the norms for “modern” C++ to get a sense of how code is normally written.

Read the rest of this article »

6 Comments

C++ For C# Developers: Part 47 – Containers Library Wrapup

Tags: , , ,

We’ve covered all the individual container types, so let’s take a step back and look at the containers library as a whole. A lot of features, like support for range-based for loops and allocator customization, are supported in all container types. Today we’ll take a look at the commonalities between the containers and see what ties them together into a cohesive library.

Read the rest of this article »

2 Comments

C++ For C# Developers: Part 40 – Utilities Library

Tags: , , , , ,

Today we’ll continue to explore the C++ Standard Library by delving into its utility classes and functions. These extremely common tools provide us with basics like std::tuple whose C# equivalent is so essential it’s built right into the language.

Read the rest of this article »

4 Comments

C++ For C# Developers: Part 21 – Casting and RTTI

Tags: ,

Now that we’ve seen how types are implicitly converted in C++, we can see how they’re explicitly converted by casting. C++ offers a lot more kinds of casts than C# to control the conversion process. One of them—dynamic_cast—introduces the concept of Run-Time Type Information or RTTI, so we’ll go into that today as well.

Read the rest of this article »

4 Comments

C++ For C# Developers: Part 18 – Exceptions

Tags: , , , ,

Like C#, C++ also uses exceptions as one of its main error-handling mechanisms. Today we’ll learn all about them: throwing, catching, their impact on destructors, what happens when they go uncaught, and so much more.

Read the rest of this article »

7 Comments

Sharing IDisposables

Tags: , , ,

IDisposable is becoming more and more prevalent in Unity. Previously, it was typically only used for I/O types like FileStream. Now it’s used for in-memory types like NativeArray<T> to avoid the garbage collector. Needing to call Dispose manually means we’re explicitly managing memory, just like we’d do in lower-level languages like C++. That comes with some challenges, especially with shared ownership, which we’ll deal with today.

Read the rest of this article »

8 Comments

Simple Formula Evaluator Revisited

Tags: , , , , , ,

A couple years ago, I wrote an article showing how to empower game designers with the ability to write simple formulas like PlayerLevel*100+100. These are much more useful than just constants and don’t require any of the complexity of a real programming language. Today we’ll bring it into the Burst-compatible world and also improve its ability to handle more complex formulas.

Read the rest of this article »

5 Comments

Assertions in Burst

Tags: , , ,

Assertions are an incredibly handy tool, but do they work in Burst-compiled jobs? Today we’ll find out!

Read the rest of this article »

6 Comments

Throwing Exceptions in Burst-Compiled Jobs

Tags: , ,

Unity’s Burst compiler imposes an interesting subset of C#. The “no managed objects” rule of thumb is not always correct. Today we’ll look at eExceptions, which are managed objects but are partially supported by Burst. What’s allowed and what’s banned? Read on to find out.

Read the rest of this article »

1 Comment