Question:
Why is catch(Exception) almost always a bad idea?
Answer:
Well, if at that point you know that an error has occurred, then why not write the proper code to handle that error instead of passing a new Exception object to the catch block? Throwing your own exceptions signifies some design flaws in the project. Source: CoolInterview.com
Hi, Catch(System.Exception) is not a bad idea to use. Catch(Exception) means handling all types of errors that are thrown by the Try block. I think even throw Exception is not a bad idea to use in the Catch(Exception)to maintain stack trace. Source: CoolInterview.com
Answered by: Pavan | Date: 2/11/2010
| Contact Pavan
Hi,catch cannot be used whille debuging asp.net code as the particular error is thrown and handled by catch. but after debuging we should apply catch .. Source: CoolInterview.com
Answered by: shanky | Date: 3/20/2010
| Contact shanky
If we use multiple catches(Bcz all the exceptions are came there when the exceptions were found) means it could be a useful thing otherwise i think it is a bad one. Source: CoolInterview.com
Answered by: Suresh.K | Date: 5/7/2010
| Contact Suresh.K
Hi, Catch(Exception) is used when you are not sure that which exception will be thrown by the code. This syntax will handle all system define exception. But bad side of using this syntax is that it slowdowns the execution speed as CLR have to check each possible exception. Source: CoolInterview.com
Answered by: ankur | Date: 5/10/2010
| Contact ankur
catch(Exception) is a bad idea, because, in a code block we know what we written and each code line has its own exception returns, so it should be of those types. Instead of catch(Exception) we can do multiple catch blocks with their exception types. Source: CoolInterview.com
Answered by: Nagaraj | Date: 8/4/2010
| Contact Nagaraj
exception affects the execution speed. so maximum try to avoid exception. Source: CoolInterview.com
Answered by: selvasundar | Date: 8/5/2010
| Contact selvasundar
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|