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/
-----------------------------------------------------------------------------------
Its very cool code hmm
ReplyDeleteThanks Anil
ReplyDeletethanks buddy really interesting......
ReplyDeleteReally tricky question.and good for interview preparation
ReplyDeleteThanks for sharing Sujit
ReplyDeletethank u...Expecting more questions like this
ReplyDeleteFaltu Question Yaar
ReplyDeleteTu khudko kya shivprasad samjhta hai kya
ReplyDeleteThanks all my friends
ReplyDeletehey sujit do you plz upload more tricky programs
ReplyDeleteWow.. Its Great!!! Please post more tricky questions.. Thanks...
ReplyDeleteReally interesting !!!
ReplyDeletesometimes we go on coading....but miss these magic tricks of our favourite C#..
Thanks for sharing ....
in 1st Question i think.. there is Syntactic error:
ReplyDeleteResponse,redirect("1.aspx");
it should be Response.redirect("1.aspx"); -i guess.
Please comment
Blog is very appreciable for its content part helped me lot in career assessment and got one of the Delhi metro job vacancy for 12th pass according to my profile on Job vacancy result with 100% job assistance in some easy steps
ReplyDeleteRespect and that i have a super give: How Much Home Renovation Cost my home renovation
ReplyDelete