DivideByZeroException
was created using
new
in the
throw
statement.
Remember,
throw
throws an object. Thus, you must create an object for it to throw. That
is, you can’t just throw a type. In this case, the default constructor is used to create a
DivideByZeroException
object, but other constructors are available for exceptions.
Most often, exceptions that you throw will be instances of exception classes that you
created. As you will see later in this chapter, creating your own exception classes allows you
to handle errors in your code as part of your program’s overall exception handling strategy.
Do'stlaringiz bilan baham: |