Categories
ASP.NET

Try Catch in .NET

The Try word means “Try to execute this code”. The Catch word means “Catch any errors here”. The ex is a variable, and the type of variable it is an Exception object.

Example

Public Function Delete(ByVal fileName As String) As Boolean
	Try
		File.Delete(String.Format("{0}\{1}", ConfigurationManager.AppSettings("ImageDirectory"), fileName))
		Return True
	Catch ex As Exception
		Return False
	End Try
End Function