What types of objects can be explicitly thrown?
What will be an ideal response?
In C#, you cannot throw an object unless it is an Exception or a descendant of the Exception class. In other words, you cannot throw a double or a BankAccount. However, you can throw any type of Exception at any time, not just Exceptions of your own creation. For example, within any program you can code any of the following:
throw(new ApplicationException());
throw(new IndexOutOfRangeException());
throw(new Exception());
Of course, you should not throw an IndexOutOfRangeException when you encounter division by 0 or data of an incorrect type; you should use it only when an index (subscript) is too high or too low.
Computer Science & Information Technology