try Block

noun

say it: “TRY blok” /traɪ blɒk/

A block of code that might throw an exception, followed by catch or finally blocks that deal with it.

What is try Block in C#?

try Block — A block containing code that may throw an exception.

class OrderReader
{
    int ReadQuantity(string text)
    {
        try
        {
            return int.Parse(text);
        }
        catch (FormatException)
        {
            return 0;
        }
    }
}

In a sentence

  • “I put the file read in a try block so a missing file wouldn't crash the app.”

Level: Journeyman · More C# terms at this level

Updated

In other subjects