In C#, what is the difference Between \'Catch\', \'Catch (Exception)\', and \'Catch(Exception e)\' ?
The MSDN article on try-catch uses 2 of them in its examples, but do
In short...
Catch
without a parameter will receive any exception but provide no means to address it.
Catch (Exception)
will essentially do the same thing, because you've specified the root Exception
type. As opposed to Catch (IOException)
which would only catch the IOException
type.
Catch (Exception ex)
catches all exceptions and provides a means to address it via the ex
variable.
Read more: http://msdn.microsoft.com/en-us/library/ms173160.aspx