Unity: Debugging Part 3 — Try/Catch
Bugs are inevitable and if you don’t know how to debug, then you will be doomed. This article is the third and final part of a three part series that will take you through logs, break points, and the try/catch methods when trying to solve a problem in C# while using Unity when there is no error code.
Debugging is the term we use in programming to describe the process of identifying a problem, isolating the problem, and solving the problem. So let’s jump right into how we can solve a problem.
What Is Try/Catch?
A try/catch, or try-catch, statement is a tool that allows you to handle errors gracefully without ruining the entire code. Normally, when a piece of code produces a runtime error, the entire method may be exited. A try/catch statement would allow you to handle that error without ending the entire method.
Let’s use a quick example to showcase what the try/catch statement can do. I currently have a script that prints out all the string values in an array but goes one over causing an IndexOutOfRangeException
then prints out a debug log to say that the for loop ended.