Message-ID: <491606986.2487.1369303130172.JavaMail.email@example.com> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_2486_1502258395.1369303130172" ------=_Part_2486_1502258395.1369303130172 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
A mechanism designed to handle runtime errors or other problems (excepti= ons) inside a computer program.
Exceptions are very important, as they are raised whenever an error occu= rs in the system. (Or at least they should be.)
An exception stops the program if it is not caught.
System.DivideByZeroException: Attempted to divide by zero. at Test.Main(String argv)
Which stopped the program.
To handle the situation, exceptions must be caught.
Exceptions are either caught in a
try-ensure statement, or a
Exceptions are derived from the simple
Whoops Doing more...
This prevents the code from stopping and lets the program keep running e= ven after it would have normally crashed.
There can be multiple
except statements, in case the code c=
an cause multiple
Try-ensure is handy if you are dealing with open streams th=
at need to be closed in case of an error.
This code will be executed, whether there is an error or not. System.Exception: Something bad happened. at Test.Main(String argv)
As you can see, the
ensure statement didn't prevent the
try-except-ensure combines the two.
Problem: Something bad happened. This code will be executed, whether there is an error or not.
If you don't solve the problem in your
There are times that you want to
Exceptions of your own.
Execute is called with an improper value of
i, then the
Exception will be
In production environments, you'll want to create your own
Go on to Part 15 - Functions as Objects and Multithreading= strong>------=_Part_2486_1502258395.1369303130172--