|
-
August 19th, 2010, 04:56 PM
#1
what's the difference between these 2 catches ?
try
{
...
}
catch
{
...
}
or
try
{
...
}
catch(Exception e)
{
...
}
-
August 20th, 2010, 12:21 AM
#2
Re: what's the difference between these 2 catches ?
With the empty catch clause, you have no idea of what exception occurred.
With the Exception e param of the 2nd catch clause you catch every type of exception.
Generally you want to catch exceptions in a specific to general order.
for example, say I'm saving some data to a database and there is a possibility of having a null param or database problem
Code:
try
{
// code that could throw a ArgumentNullException or SqlException
}
catch( ArgumentNullException e )
{
// handle ArgumentNullException
}
catch( SqlException e )
{
// handle sql exception
}
-
August 20th, 2010, 04:03 AM
#3
Re: what's the difference between these 2 catches ?
Hi 5883,
Wen yo have catch{} alone yo can handle but without the knowledge wat kind of exception it is ,moreover if yo want to give user about exception and to correct him for good input its difficult with tis.
Wen yo use catch(Exception e){} Exception is not but base class for all kind of exception .SO in this usage your creating a reference for that baseclass which holds the exception created.
In that e yo have many methods and properties so that yo can handle as well as inform the user efficiently.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|