|
-
Apr 24th, 2010, 05:37 PM
#1
Thread Starter
Frenzied Member
More exception handling questions
Hi guys,
I'm still trying to make sure I am understanding structured exception handling correctly. I have a piece of code to demonstrate my question.
Code:
internal void ReadFromBinary(string PathToFile)
{
try
{
fileAsStream = new FileStream(PathToFile, FileMode.Open);
fileReader = new StreamReader(fileAsStream);
}
catch (FileNotFoundException)
{
throw; //Throw the up to the caller?
}
//Does any code from here down not get called unless the exception is handled?
}
-
Apr 24th, 2010, 06:17 PM
#2
Frenzied Member
Re: More exception handling questions
the catch will throw the exception
and if there is any codes will be added after the catch statement all these code will be called
You Don't Have to Rate Me.
I'm Not a Civilized Man I'm the Civilization it self
White or Black, Living or Dieing and 0 or 1 that's MY life
iam an Object in Object Oriented Life
my blog : http://refateid.blogspot.com/
twitter : @avrail
010011000111010101110110001000000100110101111001001000000101000001100011 
-
Apr 24th, 2010, 06:21 PM
#3
Thread Starter
Frenzied Member
Re: More exception handling questions
And if I do not want the code to be called? It hardley seems structured to use a bool and if block after the catch.
-
Apr 24th, 2010, 06:29 PM
#4
Frenzied Member
Re: More exception handling questions
you can use simple
in your method return; will make you get out of the method when you enter the catch block
You Don't Have to Rate Me.
I'm Not a Civilized Man I'm the Civilization it self
White or Black, Living or Dieing and 0 or 1 that's MY life
iam an Object in Object Oriented Life
my blog : http://refateid.blogspot.com/
twitter : @avrail
010011000111010101110110001000000100110101111001001000000101000001100011 
-
Apr 24th, 2010, 06:44 PM
#5
Re: More exception handling questions
Whaaat? Noooo.... once an exception is thrown, control is handed back to the calling error handler. So in the case posted, the throw in the catch will re-raise the error, forcing the call to the function to error. If there was an error handler around it, it will then go into that catch. If there isn't then the call to ReadFromBinary will error out. The exception will keep bubbling up the chain until there's code somewhere that handles it... code execution will then resume AT THAT POINT.
-tg
-
Apr 24th, 2010, 07:03 PM
#6
Frenzied Member
Re: More exception handling questions
amm, lol sorry i'm the one how do the wrong
i didn't see the throw; i think was wrong i must have a look for the question
my answer was if he catch the error and handled it with out the throw
sorry again
You Don't Have to Rate Me.
I'm Not a Civilized Man I'm the Civilization it self
White or Black, Living or Dieing and 0 or 1 that's MY life
iam an Object in Object Oriented Life
my blog : http://refateid.blogspot.com/
twitter : @avrail
010011000111010101110110001000000100110101111001001000000101000001100011 
-
Apr 25th, 2010, 05:52 AM
#7
Thread Starter
Frenzied Member
Re: More exception handling questions
Yeah thats what I thought but I wasn't sure of which point the code resumed at. Also Between those two lines of code numerous exceptions can occur. Can I simply just handle system.exception when I know that any exception rasied means the function should not continue?
-
Apr 25th, 2010, 07:03 AM
#8
Frenzied Member
Re: More exception handling questions
all the Exceptions comes from System.Exception
if you have Exception such FileNotFoundException you can handle it with the way you are
if you don't what the exception that will appear
Code:
catch(Exception e)
{
//// do what you want
}
You Don't Have to Rate Me.
I'm Not a Civilized Man I'm the Civilization it self
White or Black, Living or Dieing and 0 or 1 that's MY life
iam an Object in Object Oriented Life
my blog : http://refateid.blogspot.com/
twitter : @avrail
010011000111010101110110001000000100110101111001001000000101000001100011 
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
|