Busy. Please wait.
or

show password
Forgot Password?

Don't have an account?  Sign up 
or

Username is available taken
show password

why


Make sure to remember your password. If you forget it there is no way for StudyStack to send you a reset link. You would need to create a new account.
We do not share your email address with others. It is only used to allow you to reset your password. For details read our Privacy Policy and Terms of Service.


Already a StudyStack user? Log In

Reset Password
Enter the associated with your account, and we'll email you a link to reset your password.
Don't know
Know
remaining cards
Save
0:01
To flip the current card, click it or press the Spacebar key.  To move the current card to one of the three colored boxes, click on the box.  You may also press the UP ARROW key to move the card to the "Know" box, the DOWN ARROW key to move the card to the "Don't know" box, or the RIGHT ARROW key to move the card to the Remaining box.  You may also click on the card displayed in any of the three boxes to bring that card back to the center.

Pass complete!

"Know" box contains:
Time elapsed:
Retries:
restart all cards
share
Embed Code - If you would like this activity on your web page, copy the script below and paste it into your web page.

  Normal Size     Small Size show me how

Chapter 12

Exception Handling

TermDefinition
Exeption An unexpected or error condition
Exception Handling The name for the object-oriented techniques that manage such errors
Runtime Exception Unplanned exceptions that occur during a program's execution. In contrast with syntax errors that are discovered during program compilation
Java's Two Basic Classes of Errors Java includes two basic classes of errors: Error and Exception. Both of these classes descend from the Throwable class. Like all classes, these two classes descend from Object
Error Class Represents more serious error from which your program usually cannot recover. For example, there might be insufficient memory to execute a program
Exception Class Comprises less serious errors representing unusual conditions that arise while a program is running and from which the program can recover. For example, using an invalid array subscript or performing certain illegal arithmetic operations
Crash When a program ends prematurely with an error
Stack Trace History List(Stack Trace) The list or error messages after each attempted execution
Mission Critical Refers to any process that is crucial to an organization
Fault-Tolerant Applications Are designed so that they continue to operate, possibly at a reduced level, when some part of the system fails
Robustness Represents the degree to which a system is resilient to stress, maintaining correct functioning
Programs That Handle Exceptions Programs that handle exceptions appropriately are said to be more fault tolerant and robust
1. Try Block When you create a segment code in which something might go wrong, you place the code in a try block, which is a block you attempt to execute while acknowledging that an exception might occur.
2. Try Block A try block consists of the following elements... 1. The keyword try.. 2. An opening curly brace.. 3. Executable statements, including some that might cause exceptions.. 4. A closing curly brace
Catch Block A segment of code that can handle an exception that might be thrown by the try block that precedes it. To handle a thrown exception, you can code one or more catch blocks immediately following a try block
Throw Statement A statement that sends an Exception object out of a block or a method so that it can be handled elsewhere
Format of try...catch Pair try.. {.. //statements that might generate an exception.. }.. catch(Exception someException).. {.. //actions to take if exception occurs.. }
finally Block Used when you have actions you must perform at the end of a try...catch sequence. The code within a finally block executes regardless of whether the preceding try block identifies an exception
Exception Specification When a method throws an exception that will not catch but will be caught by a different method, you must use the keyword throws followed by an Exception type in the method header
Java's Two Types of Exceptions Java's exceptions can be categorized into two types... 1. Unchecked exceptions.. 2. Checked exceptions
Unchecked Exceptions Inherit from Error or RuntimeException class. Can be handled but you are not required to do so. For example, dividing by zero is type of RuntimeExceptio, and you are not required to handle this exception - you can simple let program terminate
Checked Exceptions The type that programmers should anticipate and from which program should be able to recover. All exceptions that you explicitly throw and that descend from the Exception class are checked exceptions
1. Catch or Specify Requirement Java programmers say that checked exceptionsare subject to the catch or specify requirement, which means if you throw a checked exception from a method you must do the following...
2. Catch or Specify Requirement 1. Catch it within the method.. 2. Specify the exception in you method header's throws clause... Code that uses a checked exception will not compile if the catch or specify rule is not followed
1. Writing a Method With a throws Clause in Header If you write a method with a throws clause in the header, then any method that uses your method must do one of the following... 1. Catch and handle the possible exception.. 2. Declare the exception in its throws clause.
2. Writing a Method With a throws Clause in Header The called method can then rethrow the exception to yet another method that might either catch it or throw it yet again.
Using throws Clause Example public class PriceList.. {.. private static final double[] price = {15.99, 27.88, 34.56};.. public static void displayPrice(int item) throws IndexOutOfBoundsException.. {.. System.out.println("The price is $" + price[item]);.. }.. }
Call Stack The memory location in which the computer stores the list of method locations to which the system must return
Assertion A Java language feature that can help you detect logic errors and debug a program
assert Statement You can use an assert statement to create an assertion; when you use an assert statement, you state a condition that should be true, and Java throws an AssertionError when it is not.
assert Statement Syntax assert booleanExpression : optionalErrorMessage... where booleanExpression in the assert statement should always be true if program is working correctly. optionalErrorMessage is displayed if booleanExpression is fal