Hi friends,
In the last month I had given one interview in one of the
large MNC in Pune.
In that interview, one interviewer asked me one questions
about Try Catch block in asp.net.
I liked that questions and really it’s challenging question.
Scenario 1 :-
Please find following
Code and trace the output
Try{
Response,redirect("1.aspx");
}
Catch{
Response,redirect("2.aspx");
}
finally{
Response,redirect("3.aspx");
}
|
Answer:
The Output of this one is
that it will redirect the page to 3.aspx as on try block this will throw a
redirect error but after catch block the control will go to the finally block
which will redirect the page to 3.aspx..
Scenario 2
Trace the output
Try
{
Server.Transfer("1.aspx");
}
Catch
{
Server.Transfer("2.aspx");
}
finally
{
Server.Transfer("3.aspx");
}
|
Answer:
In the Second case we are
using Server.Transfer which will directly transfer the current page to show the
contents of the page to be redirected keeping the url address as the same.. IN
this case it will move through all three blocks and would show the contents of
1.aspx, 2.aspx and 3.aspx from the main page... ie., if we are transferring
from main.aspx then it will show the contents of 1.aspx plus the content of
2.aspx and the content of 3.aspx in main.aspx..
Happy Programming!!
Don’t forget to leave your feedback
and comments below!
If you have any query mail me to Sujeet.bhujbal@gmail.com
Regards
Sujeet Bhujbal
--------------------------------------------------------------------------------
Personal Website :-http://sujitbhujbal.wordpress.com/
Facebook :-www.facebook.com/sujit.bhujbal
CodeProject:-http://www.codeproject.com/Members/Sujit-Bhujbal
Linkedin :-http://in.linkedin.com/in/sujitbhujbal
Stack-Exchange: http://stackexchange.com/users/469811/sujit-bhujbal
Twitter :-http://twitter.com/SujeetBhujbal
JavaTalks :-http://www.javatalks.com/Blogger/sujit9923/
-----------------------------------------------------------------------------------