Exceptions should never be handled by catching the general System.Exception errors, rather specific exceptions should be caught and handled.
They are handled using try catch and finally. Finally is used to cleanup code as it's always executed irrespective of whether an exception has occurred or not. E.g.
try
{
FileInfo file=new FileInfo(@"c:\file.txt")
}
catch(FileNotFoundException e)
{
//handle exception
}
Finally
{
//cleanup code here
}
If file is found, then finally will get invoked else both catch and finally will occur.
The different methods of handling the exceptions are:
try
{
// code
}
catch(Exceptiontype *etype_object)
{
// code
}
or,
try
{
// code
}
catch(Exceptiontype *etype_object)
{
throw new Custom_Exception();
}
They are handled using try catch and finally. Finally is used to cleanup code as it's always executed irrespective of whether an exception has occurred or not. E.g.
try
{
FileInfo file=new FileInfo(@"c:\file.txt")
}
catch(FileNotFoundException e)
{
//handle exception
}
Finally
{
//cleanup code here
}
If file is found, then finally will get invoked else both catch and finally will occur.
The different methods of handling the exceptions are:
try
{
// code
}
catch(Exceptiontype *etype_object)
{
// code
}
or,
try
{
// code
}
catch(Exceptiontype *etype_object)
{
throw new Custom_Exception();
}