5 Error handling
This chapter covers
- Preventing crashes in our game client
- Handling errors through error propagation
- Connecting/reconnecting to the server at runtime
- The creation of a Future which can be awaited
Up until this point in our journey, we’ve written two relatively stable pieces of software: our game client, and our game’s server. Thanks to Rust, we’ve been able to let our guard down a little more than we might have had to if we were dealing with other languages. We haven’t had to worry about running into undefined behavior from misplaced pointers, or crashes from segfaults since we’re not using unsafe code, and the Rust borrow checker has kept us in line. We’ve also been able to avoid simple mistakes and bugs that might emerge in a non statically typed language like JavaScript. It helps that we can only do so much in our game so far: namely connect to the server and fly around. As we extend our game to be more complex though, we want to be sure that we are writing code in a way that it can continue to remain robust.