.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Interview Question >> C# >> Post New Question Subscribe to Interview Questions

Why is it a bad idea to throw your own exceptions?

Posted By :Ghanashyam Nayak     Posted Date :September 09, 2010    Points :10   Category :C# 
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.

You can also find related Interview Question to Why is it a bad idea to throw your own exceptions?  below: 

Why is catch(Exception) almost always a bad idea?

  
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. (More...)

How .NET Framework 2.0 tackles the unhandled exceptions?

  
For .NET Framework 2.0,There is a change in the behavior in which on any unhandled exception, .NET Framework 2.0 just ends the worker process. This exception cannot be caught as it is in the .Net framework 2.0, and when the .Net Framework "goes down", it also crashes the application. In .NET Framework 1.0 or 1.1, unhandled exceptions were ignored.

Workaround for this is :

Add this section in your app.config file.














Thanks,
Virendra Dugar (More...)

Why is it not a good idea to insert code into InitializeComponent method when working with Visual Studio?

  
The designer will likely throw it away; most of the code inside InitializeComponent is auto-generated. (More...)

Difference between throw and throws.

  
The throw key word is used to explicitly throw an exception, while throws is utilized to handle checked exceptions for re-intimating the compiler that exceptions are being handled. It is kind of communicating to the compiler that an exception is expected to throw one or more checked exceptions.

The throws need to be used in the method's definition and also while invoking the method that raises checked exceptions. (More...)

What is difference between throw and throw new Exception()

  
throw; rethrows the original exception and preserves its original stack trace. where as,
throw ex; throws the original exception but resets the stack trace, destroying all stack trace information until your catch block (More...)

Difference between throw and throw ex?

  
Throw : Original error stack information
Throw ex: stack error of the exception will be replaced with a stack trace starting at the re-throw point (More...)

Whats the use of "throw" keyword in C#?

  
The throw keyword is used to throw an exception programatically in C#. (More...)

What is difference between the "throw" and "throw ex" in .NET?

  
If you use "throw" statement, it preserve original error stack information.
If you use "throw ex" statement, stack trace of the exception will be replaced with a stack trace starting at the re-throw point.
So it is very important to just use the throw statement, rather than throw ex because it will give you more accurate error stack information. (More...)

Difference between System exceptions and Application exceptions?

  
All exception derives from Exception Base class. Exceptions can be generated programmatically
or can be generated by system. Application Exception serves as the base class for all applicationspecific
exception classes. It derives from Exception but does not provide any extended functionality.
You should derive your custom application exceptions from Application Exception.
Application exception is used when we want to define user defined exception, while system
exception is all which is defined by .NET. (More...)

What's difference between System exceptions and Application exceptions?

  
System exceptions are common exceptions thrown by the CLR of .Net Framework. Application exceptions can be user defined exceptions thrown by the application. (More...)

What is the difference between System exceptions and Application exceptions?

  
SystemExceptions are thrown by the CLR and are of more generic nature, whereas, ApplicationExceptions are thrown by Applications. Therefore when creating a custom Exception class we should only inherit it from Application Exception and not SystemException. (More...)

Quick Links For Interview Questions Categories:
ASP.Net Windows Application   .NET Framework   C#   VB.Net   ADO.Net  
Sql Server   SharePoint   Silverlight   OOPs   JQuery   JavaScript/VBScript
Biztalk Patten/Practices .IIS WCF WPF WWF
Networking Aptitude Others   All      

Find questions, FAQ's and their answers related to .NET, C#, Vb.Net, Sql Server and many more.

 
Now you can find lots of .NET, C#, Vb.Net, SQL Server,Windows, ASP.Net related Questions and their Answers here at www.dotnetspark.com. Our aim is to help you pass your certification Exams (MCP, MCSD, MCAD etc.,) with flying scores and get good name in your company.

So, Start looking our Interview Question section daily and improve your .NET Skills. You can also help others by posting Interview Questions and their Answers in this section.


Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend