OLABs Chapter 14: Exception

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

How do you define an exception handler in Java catch several different types of exceptions?

...

What are the syntactic components of a Java exception handler?

An exception handler consists of try, catch, and finally blocks

What is an exception?

An object representing an event that occurs during the execution of a program that disrupts the normal flow of execution

How are exceptions represented in Java?

As objects as well as checked and unchecked exceptions

Explain how a method in Java can "duck" the responsibilities for handling an exception

By using the throw clause (throw keyword)

What are the differences between a checked and a run-time exception?

Checked exceptions are checked by the compiler but it is not required for a run-time exception and will only be found to debug by running and testing the application

What advantages does exception handling have over traditional methods of error handling?

Error handling code are separated from the main stream code, the can be propagated through the stack method, and fine grained differentiation between error groups and different types of errors`

*How can you create your own types of exceptions in Java?

First define the class that would represent the specific event. This exception can be thrown inside any method or constructor. void openFile(String name) throws FileNotFound Exception {

What is the motivation for Java's "specify and catch" exception handling requirement?

The public signature that enables the callers of a method to know about the exceptions that a method may throw so that they can decide what to do about those exceptions if they arise

*Why should you not write "generic" exception handlers?

They can make code more error prone by catching and handling exceptions that were not anticipated by the programmer and for which the exception handler was not intended

*When is the final block executed?

When no exception is thrown, immediately after leaving the try block

How do you write a "generic" exception handlers?

try{ ... } catch<Exception e> {...}


Kaugnay na mga set ng pag-aaral

CHAPTER 8: PHOTOSYNTHESIS questions

View Set

PathoPharm Quiz 3 review questions

View Set

Maternal Purple Book questions chapters 26-29

View Set

CFA 2.33 Discounted Dividend Valuation

View Set