Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Exceptions - Introduduction to Jave Programming - Lecture Slides, Slides of Java Programming

In the course of the Introduction to Jave Programming, we study the basic syntax and the basic program in java. In these lecture slides the key points are:Exceptions, Throw and Catch, Runtime Errors, Programming, Two Major Parts, Normal Execution, Treat Unusual Events, Encountered Runtime Errors, Coding Experiences, Runtime Error Happens

Typology: Slides

2012/2013

Uploaded on 04/23/2013

sarmistha
sarmistha 🇮🇳

3.8

(22)

113 documents

1 / 11

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Intro. to Exceptions
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Exceptions - Introduduction to Jave Programming - Lecture Slides and more Slides Java Programming in PDF only on Docsity!

Intro. to Exceptions

Highlights

  • try, throw and catch

Runtime errors

You have no doubt encountered runtime errors during your coding experiences Normally when a runtime error happens, the angry red text appears and stops your program Your program can actually continue running if you use try and catch block

try, throw catch

A try block simply has the word try before it If a runtime error (or a specific error) happens inside this try block, you will be thrown to the catch block

Manual exceptions

You can define your own exceptions if you do not want to use an existing one: The above is using throw with Exception constructor (takes one String argument) (See: ManualException.java)

Exception class

Just as Object is the parent to all classes, Exception is the parent to all exceptions This means if you write: catch(Exception e) then it will catch all runtime exceptions If the exception in your catch does not match the exception that happened in try, then your code will have a normal runtime error

Multiple catch

You can use multiple catch statements for a single try block Only the first catch statement which satisfies the exception will run (If you put catch(Exception e) as first catch, then you will never get to later ones) (See: MultiCatch.java) Docsity.com