Module 8 Try ,Catch, and Finally Blocks in Java

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

What subclasses are apart of RuntimeException? (found by using try-catch blocks)

1. ArithmeticException 2. IndexOutOfBoundsException 3. IllegalStateException 4. NegativeArraySizeException * See word for more details*

What are the method s of the Throwable class?

1. getMessage 2. toStribg 3. initCause 4. printStackTrace Ex: See Word

what are the four Throwable Constructors

1. public Throwable() 2. public Throwable(String message) 3. public Throwable(Throwable cause) 4. public Throwable(String message, Throwable cause)

What happens if an exception occurs in a try block and is not caught in the catch block?

A finally block will be executed if present considering it is optional. The application will then be terminated.

RuntimeException class

A subclass of Exception and its subclasses describe exception objects that are thrown automatically by the JV< at runtime.

Contract-programming

A technique used to ensure a high level of software quality, reusability, and reliability.

Java's exception-handling code is specified within what kind of block?

A try...catch...finally block

The type of exception for each catch block is specified as what?

As an argument to catch statement.

Objective

Be able to specify the code required to use try, catch, and finally blocks to handle exceptions in Java for a given scenario.

How can you enable and disable assertions?

By using command line switched at runtime.

General Catch block

Catches all exceptions. Must be positioned after the specific catch blocks,

Exception Changing

Enables you to keep track of the original exception that was thrown.

setUncaughtExceptionHandler Method

Enables you to take full control of a thread's response to an uncaught exception handler for a particular thread.

What are the subclasses of Throwable

Error and Exception *See Word for more details*

In the code, a divide-by-zero exception is an ArithmeticException instance.

Ex: See Word

What are the two types of catch blocks.

General and Specific

Java enables exceptions to be created and thrown. What are they?

Implicitly and Explicitly *See Word for details*

***Note***

It is good practice to use assertions to test assumptions regarding internal invariants, control-floe invariants, preconditons, postconditions, and class invariants.

What is the Finally block?

Its optional if a try block already has an associated catch block. If you have a finally block, the code it contains always executes, regardless of whether the exceptions are thrown or not. ***NOTE*** If a system.exit occurs in the code, in which case the application terminates without executing a finally block is the ONLY exception to this rule. Ex: See Word

why do you have exceptions?

Maybe a result of an invalid or out-of-range arguments being passed to methods.

Topic: Working with exceptions in Java 6.0

Objective: Create an exception subclass for a given code sample, and implement exception handlers on a thread basis.

Topic: Throwing exceptions in Java

Objective: Handle exceptions calling methods, create and throw exceptions explicitly, and use exception chaining to set the cause of a thrown exception.

Topic: The assertion Mechanism in Java

Objective: Identify the code used to identify the code used to create a Java assertion statement for a given scenario, and specify the commands and flags used to create and compile assertions.

Topic: The Java Exception class hierarchy

Objective: You should be able tp specify the appropriate method of Throwable class to use in a given piece of code, and associate runtime and checked exceptions with the events that throw.

What are the two forms of the assertion statement?

Simple assertion statement Complex assertion statement *See word for details*

What is a protected code?

The code in a try block Ex: See word

What are catch blocks?

They specify exception handlers for the types of exceptions thrown. If not exception is thrown, then the code in the catch block doesn't run b/c it isn't needed. Ex: See Word

To set the handler for all threads, you pass an implementation of the....

Thread.UncaughtExceptionHandler

All Java exceptions and errors are subclasses of a class in the java.lang package called?

Throwable *NOTE*... Only an object of type throwable can be thrown in code, including exceptions and system errors.

Specific catch blocks

Will never be checked

Assertion

enables you to test an assumption about how a program works while your application is running. 2. Contains a Boolean expression- w/ a default value of true. 3.They check conditions that should never be violated. 4. Ensures that a rule about something in your code should never change.


Set pelajaran terkait

Chapter 9: Pneumatic Actuators, Dampers, and Valves

View Set

El Examen Psiquiátrico del Paciente

View Set