Save
Busy. Please wait.
Log in with Clever
or

show password
Forgot Password?

Don't have an account?  Sign up 
Sign up using Clever
or

Username is available taken
show password


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.
Your email address is only used to allow you to reset your password. See 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.
focusNode
Didn't know it?
click below
 
Knew it?
click below
Don't Know
Remaining cards (0)
Know
0:00
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
Popular Engineering sets

 

 



Voices

Use these flashcards to help memorize information. Look at the large card and try to recall what is on the other side. Then click the card to flip it. If you knew the answer, click the green Know box. Otherwise, click the red Don't know box.

When you've placed seven or more cards in the Don't know box, click "retry" to try those cards again.

If you've accidentally put the card in the wrong box, just click on the card to take it out of the box.

You can also use your keyboard to move the cards as follows:

If you are logged in to your account, this website will remember which cards you know and don't know so that they are in the same box the next time you log in.

When you need a break, try one of the other activities listed below the flashcards like Matching, Snowman, or Hungry Bug. Although it may feel like you're playing a game, your brain is still making more connections with the information to help you out.

To see how well you know the information, try the Quiz or Test activity.

Pass complete!
"Know" box contains:
Time elapsed:
Retries:
restart all cards