Message-ID: <2037941957.8726.1414217057150.JavaMail.firstname.lastname@example.org> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_8725_541879491.1414217057149" ------=_Part_8725_541879491.1414217057149 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
Exceptions are very important, as they are raised whenever an error occu= rs in the system. (Or at least they should be.)=20
An exception stops the program if it is not caught.=20 =20
System.DivideByZeroException: Attempted to divide by zero. at Test.Main(String argv)=20
Which stopped the program.=20
To handle the situation, exceptions must be caught.
ns are either caught in a
try-except statement, a
try-ensure statement, or a
Exceptions are derived from the simple
Whoops Doing more...=20
This prevents the code from stopping and lets the program keep running e= ven after it would have normally crashed.=20
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)=20
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.=20
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
Go on to Part 15 - Functions as Objects and Multithreading= strong>