Exforsys

Free Training

Generic Exception Handling

This is a discussion on Generic Exception Handling within the C Sharp forums, part of the Programming Talk category; I have written an exception in my C# code as below: catch(FileNotFoundException example) { Console.WriteLine(example.ToString()); } But the above would ...

Go Back   Exforsys > Programming Talk > C Sharp

Exforsys.com


C Sharp C# Questions and Discussions

Reply

 

LinkBack Thread Tools Search this Thread
  #1 (permalink)  
Old 05-02-2007, 04:37 PM
Senior Member
 
Join Date: Apr 2006
Posts: 122
rachelle is on a distinguished road
Question Generic Exception Handling

I have written an exception in my C# code as below:
catch(FileNotFoundException example)
{
Console.WriteLine(example.ToString());
}

But the above would only catch exceptions when FileNotFoundException exception is thrown. I want to handle and catch other generic Exceptions also. How can I write exception for these?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-10-2007, 09:23 AM
Senior Member
 
Join Date: Apr 2006
Posts: 162
sammy is on a distinguished road
The following would handle and catch other generic Exceptions
catch (Exception e1)
{
.................
...................
}
In the catch block you can write code that does general error handling.
finally
{
.................
...................

}

In the above finally clock you can write code so that the whatever written in finally block of code gets executed irrespective of before events.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 10-10-2007, 09:01 AM
Junior Member
 
Join Date: Oct 2007
Posts: 1
anandh_exforsys is on a distinguished road
Exception handling

hi,

try
{
...
}

catch(FileNotFoundException example)
{
Console.WriteLine(example.ToString());
}

catch(Exception e)
{
Console.WriteLine(example.ToString());
}

while doing this, if u got FileNotFoundException, the first catch block will execute, for any other exceptions, the generic exception catch block will execute...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads

Thread Thread Starter Forum Replies Last Post
VB exception handling problems dababy Visual Basic Tutorials 1 11-30-2006 06:48 PM
Visual Basic : Make the Transition from Traditional Visual Basic Error Handling to the Object-Oriented Model in .NET techguru Visual Basic Tutorials 0 08-29-2005 07:27 AM
Visual Basic : .NET Remoting and Event Handling in VB .NET, Part 2 techguru Visual Basic Tutorials 0 08-28-2005 07:27 PM
Visual Basic : .NET Remoting and Event Handling in VB .NET, Part 3 techguru Visual Basic Tutorials 0 08-28-2005 03:26 PM
comp.lang.c Answers to Frequently Asked Questions (FAQ List) Steve Summit Tech FAQ 0 06-01-2004 07:00 AM


All times are GMT -4. The time now is 10:14 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0
Copyright 2004 - 2009 Exforsys Inc. All rights reserved.