New User Special Price Expires in

Let's log you in.

Sign in with Facebook


Don't have a StudySoup account? Create one here!


Create a StudySoup account

Be part of our community, it's free to join!

Sign up with Facebook


Create your account
By creating an account you agree to StudySoup's terms and conditions and privacy policy

Already have a StudySoup account? Login here


by: Mallie Crist


Marketplace > Georgia State University > ComputerScienence > CSC 2310 > PRIN OF COMPUTER PROGRAMMING
Mallie Crist
GPA 3.62

Louis Henry

Almost Ready


These notes were just uploaded, and will be ready to view shortly.

Purchase these notes here, or revisit this page.

Either way, we'll remind you when they're ready :)

Preview These Notes for FREE

Get a free preview of these Notes, just enter your email below.

Unlock Preview
Unlock Preview

Preview these materials now for free

Why put in your email? Get access to more of this material and other relevant free materials for your school

View Preview

About this Document

Louis Henry
Study Guide
50 ?




Popular in Course

Popular in ComputerScienence

This 6 page Study Guide was uploaded by Mallie Crist on Monday September 21, 2015. The Study Guide belongs to CSC 2310 at Georgia State University taught by Louis Henry in Fall. Since its upload, it has received 15 views. For similar materials see /class/209886/csc-2310-georgia-state-university in ComputerScienence at Georgia State University.

Popular in ComputerScienence




Report this Material


What is Karma?


Karma is the currency of StudySoup.

You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!

Date Created: 09/21/15
Programming I Java Exceptions Handling in Java Exceptions in Java Compilers catch errors that occur at compilation time but not runtime errors Java tries to deal with runtime error as well by using exception handlers Exception error in the program that occurs during its execution and disrupts the normal ow of instructions Exception is a shorthand for exceptional event Examples division by zero trying to access an outofbounds array elements trying to open a le that does not exists etc Java tries to deal with errors in a more uni ed manner When such an error occurs an exception object is created This object contains information about the type of the error and the state of the program when the error occurred The exception object is then passed to the runtime system and it is responsible to nd some code to handle the error Why use exceptions instead of return values Forces error checking Cleans up your code by separating the normal case from the exceptional case The code isn39t littered with a lot of if else blocks checking return values Low overhead for nonexceptional case Separating Error Handling Code from quotRegularquot Code Propagating Errors Up the Call Stack Grouping Error Types and Error Differentiation Throwing an exception in Java terms creating an exception object and handling it to the runtime system to process it Look at this later Exceptions An exception is an object that describes an unusual or erroneous situation Exceptions are thrown by a program and may be caught and handled by another part of the program A program can therefore be separated into a normal execution ow and an exception execution ow An error is also represented as an object in Java but usually represents a unrecoverable situation and should not be caught A program can deal with an exception in one of three ways 0 ignore it o handle it where it occurs 0 handle it an another place in the program The manner in which an exception is processed is an important design consideration Louis Henry Page 1 30072010 Programming I Java Exception Handling If an exception is ignored by the program the program will terminate and produce an appropriate message The message includes a call stack trace that indicates on which line the exception occurred The call stack trace also shows the method call trail that lead to the execution of the offending line Categories of Exceptions Checked Exceptions versus Unchecked Checked exception Must either be caught or declared within the method where it is thrown Monitored by the Java compiler amp Runtime Example IOException Unchecked exceptions belong to a subclass of RuntimeException Not monitored by the compiler are subclasses of the RuntimeException class do NOT need to be handled in order for the program to compile do need to be handled if you don t want your program to die when an exception is thrown Example This program below will throw an ArithmeticException when the diVide method is called with zero as the denominator Since ArithmeticException is a subclass of RuntimeException it is an unchecked exception This program below will compile but when it runs an ArithmeticException will be thrownAnd since this rithmeticException is not handled the program will die Louis Henry Page 2 30072010 Programming I Java public class UncheckedOne public static void mainString args int qa divide5 2 Systemoutprintlnqa int qb divide5 0 Systemoutprintlnqb public static int divideint numerator int denominator return numeratordenominator The t1y Statement To process an exception when it occurs the line that throws the exception is executed within a try block A try block is followed by one or more catch clauses which contain code to process an exception Each catch clause has an associated exception type When an exception occurs processing continues at the rst catch clause that matches the exception type An exception is either checked or unchecked A checked exception can only be thrown within a try block or within a method that is designated to throw that exception The compiler will complain if a checked exception is not handled appropriately An unchecked exception does not require explicit handling though it could be processed that way Catching an exception One of the advantages of Java exception handling is that it allows you to concentrate on the problem you are trying to solve in one place and then dealing with the errors from that code in another place This is done by using try blocks and catch blocks in Java code try code that might generate exceptions catch Exceptionl ex1 handle exceptions of type Exceptionl Louis Henry Page 3 30072010 Programming I Java catch Exception2 ex2 handle exceptions of type Exception1 catch Exception3 ex3 handle exceptions of type Exception1 etc Key to Remember Exceptions can be handled in 2 ways 1 Catch the exception in the method in which it is thrown 2 Append a clause to the method signature that noti es users that the method may throw an exception This program demonstrates the rst way catch the exception in the method in which it is thrown public class UncheckedTwo public static void mainstring args int qa divide5 2 Systemoutprintlnqa int qb divide5 0 Systemoutprintlnqb public static int divideint numerator int denominator int result 0 try result numeratordenominator catchArithmeticException ex Systemoutprintlnex result 0 return result Louis Henry Page 4 30072010 Programming I Java In the try block you quottryquot your various method calls here In the catch block you code the exception handlers The handlers must appear directly after the try block If an exception is thrown the exception handling mechanism goes hunting for the rst handler with an argument that matches the type of the exception Then it enters that catch clause and the exception is considered handled The search for handlers stops once the catch clause is nished Only the matching catch clause executes Within the try block a number of different method calls might generate the same exception but you need only the handler Finally Block The nally block is actually a catch block and it is optional if it is present it is placed after the last ofa try block s catch blocks try code that might generate exceptions catch Exceptionl ex1 handle exceptions of type Exceptionl catch Exception2 ex2 handle exceptions of type Exceptionl catch Exception3 ex3 handle exceptions of type Exceptionl finally free the resources Java guarantees that a final ly block if one is present will be executed regardless of whether or not any exception is thrown in a try block or any of tits corresponding catch blocks Java also guarantees that a finally block will be executed ifa try block is exited via a return break or continue statement Resourcerelease code is placed in a nally block Suppose a resource is allocated in a try block If no exception occurs the catch handlers are skipped and control proceeds to the final ly block which frees the resource and control proceeds to the rst statement after the f i na 1 l y block Standard Java Exceptions Java contains a class called Throwable that describes everything that can be thrown as an exception Java exceptions are packages libraries and methods speci c Louis Henry Page 5 30072010 Programming I Java Some j ava lang package exceptions Exception ClassNotFoundException IllegalAccessException NoSuchFieldException NoSuchMethodException RuntimeException ArithmeticException IllegalArgumentException IllegalThreadstateException NumberFormatException IllegalStateException IndexOutOfBoundsException ArrayIndexOutOfBoundsException StringIndexOutOfBoundsException SecurityException Some java 10 package exceptions Exception IOException CharConversionException EOFException FileNotFoundException InterruptedIOException ObjectStreamException UnsupportedCodingException UTFDataFormatException Exception guidelines use exceptions to 0 Fix the problem and call the method which causes the exception again Continue without retrying to execute the method again Do something else e g calculate some alternative result instead of what the method was supposed to do Do whatever you can in the current context and rethrow the same exception to a higher contest Do whatever you can in the current context and throw a different exception to a higher contest Terminate the program Louis Henry Page 6 30072010


Buy Material

Are you sure you want to buy this material for

50 Karma

Buy Material

BOOM! Enjoy Your Free Notes!

We've added these Notes to your profile, click here to view them now.


You're already Subscribed!

Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'

Why people love StudySoup

Bentley McCaw University of Florida

"I was shooting for a perfect 4.0 GPA this semester. Having StudySoup as a study aid was critical to helping me achieve my goal...and I nailed it!"

Allison Fischer University of Alabama

"I signed up to be an Elite Notetaker with 2 of my sorority sisters this semester. We just posted our notes weekly and were each making over $600 per month. I LOVE StudySoup!"

Steve Martinelli UC Los Angeles

"There's no way I would have passed my Organic Chemistry class this semester without the notes and study guides I got from StudySoup."

Parker Thompson 500 Startups

"It's a great way for students to improve their educational experience and it seemed like a product that everybody wants, so all the people participating are winning."

Become an Elite Notetaker and start selling your notes online!

Refund Policy


All subscriptions to StudySoup are paid in full at the time of subscribing. To change your credit card information or to cancel your subscription, go to "Edit Settings". All credit card information will be available there. If you should decide to cancel your subscription, it will continue to be valid until the next payment period, as all payments for the current period were made in advance. For special circumstances, please email


StudySoup has more than 1 million course-specific study resources to help students study smarter. If you’re having trouble finding what you’re looking for, our customer support team can help you find what you need! Feel free to contact them here:

Recurring Subscriptions: If you have canceled your recurring subscription on the day of renewal and have not downloaded any documents, you may request a refund by submitting an email to

Satisfaction Guarantee: If you’re not satisfied with your subscription, you can contact us for further help. Contact must be made within 3 business days of your subscription purchase and your refund request will be subject for review.

Please Note: Refunds can never be provided more than 30 days after the initial purchase date regardless of your activity on the site.