How to avoid NRE when reading the tag of a button C# : <p>(Sobbing out of frustration)</p>

<p>How do you avoid annoying NRE in this case? The output of the code is correct, but I wish to get rid of the NRE.</p>

<p>Background:</p>

<p>There are some buttons on a form, some of which represent seats of a classroom. The other buttons are irrelevant because I only need the seat buttons, and only the seat buttons have tags that has value.</p>

<p>So, I loop through all buttons and read their tags, if it is not empty, then keep that button in a list. The rest are ignored.</p>

<p>However, when the code is run, NRE pops up at the fourth line, the line starting with "try".</p>

<pre><code>foreach (Button seatbutton in this.Controls)
 {
   string betta;
   try { betta = seatbutton.Tag.ToString(); }
   catch { betta = ""; }

   if (!string.IsNullOrEmpty(betta))
    {
     seatbuttons.Add(seatbutton);
    }
 }
</code></pre>

<p>This is the shortest, most straightforward example of this type of NRE in my code. There are several more.</p>

<p>I have searched the web, and most responses are among the lines of: "Bad coding habits caused this."</p>

<p>As you can probably tell, I'm quite new at this whole thing and haven't even had the time to build habits yet. Can you guys help? Perhaps with some tips for GOOD coding habits?</p>

<p>T_T thanks!</p>
