block is the way you do it:
... code which may cause a problem ...
catch (exceptionType exceptionVariable)
... code to handle the exception ...
allows you to access information on why the exception happened.
allows you to handle just the exceptions you can deal with: for all exceptions use
, but you could handle just SQL database exceptions with the SqlException class:
catch (SqlException ex)
You should use the most specific Exception you can handle.
For more information, read up on try-catch - C# Reference | Microsoft Docs