return, ends the method, in this case the main procedure, so you are
telling the program to end in this case.

about the error, look at where you have the initialization of fin and
fout, they are inside of a try block, if it initializes OK then the
code continues.

If fin fails to initialize the catch will get any
FileNotFoundException, given the parameters, and checking to MSDN
documentation, FileNotFoundException is the unique exception that may
happen. now look the code in the catch, it says that the program ends,
so no futher execution. so Visual Studio syas: "ah, if the code
reached here where VIKAS GARG, uses the fin variable, it got to be
initialized", if you take out the return, there is the the possibility
of it being not initialized, so you get the error.

[the same is applicable for fout and it's own try block]

Great explanation given alfansa
Yes I have initialized fin and fout in the try block
because they may throw exception
while reading a file there may be FileNotFoundException
and while writing to a file there can be IOException
thus I have coded them in try block
OK lets leave this this is not the point of argue
main problem is

In line no 37 I have used return statement
and in exception handling I had studied that if we are not having any
exception in try block then

no catch block is executed
thus the catch block which is on line no. 45 will not be executed and will
be jumped
if if this catch block has been executed then the output should be displayed
because I have used
            Console.WriteLine(exc);
in that catch block and it is not giving any output this means that that
catch blocked is not

executed

then is I remove return, from there
what is problem in that

Also please can anyone tell what is return used for in catch block

Reply via email to