What is the difference between
try
{
//Some code
}
catch
{
}
and
try
{
//Some code
}
catch(Exception)
{
}
What is the difference between
try
{
//Some code
}
catch
{
}
and
try
{
//Some code
}
catch(Exception)
{
}
Nothing I believe in the case you have shown, however using the second example you can catch specific kinds of exceptions. For example:
try
{
//Some code
}
catch(NullReferenceException Ex)
{
}
Would catch any exceptions of type NullReferenceException
Your first example catches ALL exceptions. Your second example just catches one specific exception. You can have multiple catch clauses and you can even write your own exceptions derived from the Exception class.
Your second example just catches one specific exception.
It catches all exceptions that are a subclass of Exception
. Since every exception is a subclass of Exception
, that means it catches all exceptions -- just like the first one.
also
try
{
//Some code
}
catch(Exception ex)
{
}
allows you to trap user input errors that you can notify the user of.
I guess you should definitely do through this article...
http://www.codeproject.com/Articles/15146/Exception-handling-in-C-and-ASP-Net
allows you to trap user input errors that you can notify the user of.
That will catch any exception, not just user input errors.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.