Submit Interview FAQ
Home » Interview FAQ » C#RSS Feeds

When should I throw an exception?

  Shared By: Chad Bradley    Date: Oct 07    Category: C#    Views: 612


This is the subject of some debate, and is partly a matter of taste. However, it is accepted by most that exceptions should be thrown only when an 'unexpected' error occurs. How do you decide if an error is expected or unexpected? This is a judgement call, but a straightforward example of an expected error is failing to read from a file because the seek pointer is at the end of the file, whereas an example of an unexpected error is failing to allocate memory from the heap.


Didn't find what you were looking for? Find more on When should I throw an exception? Or get search suggestion and latest updates.

Your Comment
  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].