Last post Mar 18, 2014 02:24 PM by gerrylowry
Mar 18, 2014 01:00 AM|srajeshkumar|LINK
Last week i had question, is there any exception not being caught using below catch block, please confirm..
//code block here
Mar 18, 2014 01:10 AM|gerrylowry|LINK
srajeshkumar welcome to forums.asp.net
AFAIK, no ... however, there are reasons why your exception may appear to be not working.
in general terms:
//code block here
(a) your exception will be caught BUT nothing will happen because your catch block is empty
(b) an exception might happen elsewher and be caught
(c) you may expect an exception and none occurs (false expectation)
// ill behaved code block here, example:
Int32 blowMeUp = Int32.Parse("1.234");
throw; // this should catch the above error as a FormatException: "Input string was not in a correct format".
end of edit.
Mar 18, 2014 01:15 AM|srajeshkumar|LINK
Thanks for the reply,
my question was apart from only one exception all other exceptions can be caught using above code, so what would be the one exception that can't be caught using above code block.
Mar 18, 2014 01:28 AM|gerrylowry|LINK
Sorry, but i'm not sure i understand your issue.
it would likely help you formulate your question with more clarity if first you study these MSDN links:
"How to: Use the Try/Catch Block to Catch Exceptions"
"try-catch-finally (C# Reference)"
"Exception Handling Fundamentals"
Perhaps you might make your question clearer by being more specific and/or providing an example of some code that is causing you grief?
You may find this helps you formulate your questions:
Mar 18, 2014 02:15 AM|srajeshkumar|LINK
Lastweek i had interview question,
Question: all exception can be caught using the Exception base class except one exception what is that exception?
also am not sure above the answer
Mar 18, 2014 11:44 AM|nijhawan.saurabh|LINK
There are 2 possibilites:
In case your process gets killed/ stops execution of your program - This scenario would leaa to not executing your catch block.
And uncatchable exceptions(Example - Application.FailFast Exception):
Mar 18, 2014 12:06 PM|PatriceSc|LINK
If I remember stack overflow or out of memory are never caught by a catch clause (the problem being that then you can't even keep running your code).
If you have a problem tell directly about this problem, it will be easier to help. Or is it just a question you had in an interview or something ?
Mar 18, 2014 12:23 PM|Rion Williams|LINK
I believe that PatrickSc is correct as there are a few exceptions that will not be captured by a catch block :
You can read more on this topin within
this Stack Overflow discussion and
this other related discussion.
Mar 18, 2014 02:24 PM|gerrylowry|LINK
@ Rion William...
a StackOverflowException ... presumably that would be when 5 overzealous SO members perform a forced close on a reasonable question.
FWIW, any coded exception (i.e., the code that catches the exception) has a good chance of being caught, although not necessarily within the program whose code caused that exception ... otherwise, the .NET Framework architects would not be creating classes
public class OutOfMemoryException : SystemException
Some exceptions are difficult to catch, but preventable, such as OMG someone kicked to power cord out of the wall socket.
So, when we talk about catching exceptions, an interview question like the one asked of
srajeshkumar is a bit unfair imho.
That question itself lacks clarity:
ALL exception can be caught using the Exception base class
except ONE exception what is that exception?
Rion has researched and listed FIVE ...
@ srajeshkumar ... did your interviewers tell you the answer? if not, why not share what you've learned here with them and ask them what the
ONE exception is; if they are willing to share, i'd be very interested in hearing their answer. FWIW, i'd rather hire someone like yourself who makes a serious effort to fill her/his knowledge gaps. There are books one can purchase that list
trick interview questions; there are interviewers and candidates who purchase such books ~~ i'd rather hire someone who can actually program and who cares about her/his craft. imnsho, interviewers who filter out candidates with obscure questions are often
throwing out the baby with the bath water.