When to use and when not to use Try Catch Finally

asked15 years ago
last updated15 years ago
viewed5.6k times
Up Vote12Down Vote

I am creating asp.net web apps in .net 3.5 and I wanted to know when to use and when not to use Try Catch Finally blocks? In particular, a majority of my try catch's are wrapped around executing stored procs and populating textfields or gridviews? Would you use Try Catch when you execute a stored proc and populated a data display control?

My code block usually looks like:

protected void AddNewRecord()
    {
        try
        {
           //execute stored proc
           // populate grid view controls or textboxes
        }
        catch (Exception ex)
        {
           //display a messagebox to user that an error has occured
           //return
        }
        finally
        { }
   }