Objektorienteeritud programmeerimine MTAT (6 EAP) 9. Loeng. H e l le H e i n h e l l e. h ee

Size: px
Start display at page:

Download "Objektorienteeritud programmeerimine MTAT (6 EAP) 9. Loeng. H e l le H e i n h e l l e. h ee"

Transcription

1 Objektorienteeritud programmeerimine MTAT (6 EAP) 9. Loeng H e l le H e i n h e l l e. h ein@ut. ee

2 Täna loengus: Erindid Erindite töötlemine Võtmesõnad try, catch, throw, throws, finally, assert 2

3 Millest vead (tõrked) tekivad? Koodi või andmete viga - nt. vale tüübiteisendus, massiivi sobimatu indeksi kasutamine, avaldises nulliga jagamine, Vead standardmeetodite kasutamisel - nt. kui kasutada substring() meetodit sõne töötlemisel, võime saada vea (erindiklassi ) StringIndexOutOfBoundsException Ise tekitades - Ebasoovitava olukorra avastamisel programmi töö käigus, nt arvelt soovitakse rohkem raha välja võtta kui seal on, jne Java vead - Tekivad JVM-s, mis käitab kasutaja kompileeritud programmi; tavaliselt tekib programmi veast 3

4 Erindid Vea (tõrke) avastamisel tekib eriolukord (exception), mida nimetatakse erindiks. Erindi tekkimisel genereerib Java isendi antud erinditüübile vastavast objektist. See sisaldab infot vea iseloomu kohta. Eriolukord on sündmus, mis katkestab käskude täitmise normaalse järjekorra programmi töö käigus. 4

5 Olgu meil programm: Töötlemata erindid class Erind1 { public static void main(string[] args) { int b = 0; int a = 35 / b; Selle käivitamisel saame järgmise teate: Muudame programmi: class Erind2 { static void jaga() { int b = 0; int a = 35 / b; public static void main(string[] args) { Erind2.jaga(); stack trace 5

6 Erindite töötlemine Erindeid saab töödelda kasutades katsendidirektiivi (try) ja püünist (catch) Üldkuju: try { // koodiosa, milles vea tekkimist jälgitakse catch (SpecificExceptionType exob) { // vea töötlemine erindi SpecificExceptionType korral catch (OtherExceptionType exob) { // vea töötlemine erindi OtherExceptionType korral catch (GeneralExceptionType exob) { // vea töötlemine erindi GeneralExceptionType korral... finally { // kood, mis täidetakse õnnestumise ja ebaõnnestumise korral 6

7 Erindite töötlemine Kasutame eelmise programmi korral püünist (try): class Erind3 { public static void main(string[] args) { int a, b; try { b = 0; a = 35 / b; System.out.println("Seda ei väljastata."); catch (ArithmeticException e) { System.out.println("Nulliga jagamine."); System.out.println("See on peale pyynist."); 7

8 Erindite töötlemine Katsendidirektiiv (try) ja püünis (catch) moodustavad terviku. Nende vahel ei tohi olla koodi. Samuti ei tohi olla koodi püünise ja bloki finally vahel. Püünise skoop on piiratud lausetega talle vahetult eelnevas katsendidirektiivis; ta ei saa töödelda erindeid, mis on tekkinud teistes try blokkides, välja arvatud üksteisesse sisestatud try blokid. Püünise eesmärk on lahendada olukord ja võimalusel jätkata programmi tööd. Püüniseid otsitakse esinemise järjekorras kuni sobiva leidmiseni. 8

9 Töö jätkamine peale erindi töötlemist public class Erind4 { public static void main(string[] args) { int i = 10; for(int j = -1 ;j<= 2 ; j++){ try { System.out.println("Try blokki sisse i = "+ i + " j = " + j); System.out.println(i/j); System.out.println("Try blokist välja"); catch(arithmeticexception e) { System.out.println("Tekkis viga: " + e); System.out.println("Peale try blokki"); Try blokki sisse i = 10 j = Try blokist valja Try blokki sisse i = 10 j = 0 Tekkis viga: java.lang.arithmeticexception: / by zero Try blokki sisse i = 10 j = 1 10 Try blokist valja Try blokki sisse i = 10 j = 2 5 Try blokist valja Peale try blokki 9

10 Programmi täitmine juhul kui erindit ei teki 10

11 Programmi täitmine erindi korral 11

12 try { // 1 kood, mis võib tekitada erindi // 2 catch (IOException e) { // 3 kood, mis võib tekitada erindi // 4 finally { // 5 // 6 Olukorrad: 1. Erindit ei teki. Täitmise järjekord: 1, 2, 5, Erind tekib ja ta püütakse. Täitmise järjekord: 1, 3, 4, 5, 6. Kui catch tekitab erindi, siis see suunatakse väljakutsujale ja täitmise järjekord on: 1, 3, Kood tekitab erindi, mida ei püüta. Erind suunatakse väljakutsujale. Täitmise järjekord: 1, 5. 12

13 Java sisseehitatud erindiklassid erindiklassid.pdf 13

14 RuntimeException erindiklassid Kompilaator lubab need jätta töötlemata, vaatame mõnda neist Erind ArithmeticException IndexOutOfBoundsException NegativeArraySizeException NullPointerException ClassCastException IllegalArgumentException Millal tekib Viga aritmeetikas, nt katse jagada nulliga Katse kasutada massiivi indeksit väljaspool massiivi kehtivuspiirkonda. Katse defineerida massiivi negatiivse dimensiooniga. Katse kasutada muutujat, mis peaks viitama objektile, kuid viit (osuti) puudub. Katse teisendada muutujat objekti tüübiks, mis pole võimalik. Katse edastada meetodile mittekooskõlalisi argumente. 14

15 Mitme püünise (catch) kasutamine class MituCatchi { public static void main(string[] args) { try { int a = args.length; System.out.println("a = " + a); int b = 20 / a; int[] c = {2; c[25] = 100; catch(arithmeticexception e) { System.out.println("Jagamine nulliga: " + e); catch(arrayindexoutofboundsexception e) { System.out.println("Massiivi indeks vigane: " + e); System.out.println("Peale try/catch blokki."); >java MituCatchi a = 0 Jagamine nulliga: java.lang.arithmeticexception: / by zero Peale try/catch blokki. >java MituCatchi argument a = 1 Massiivi indeks vigane: java.lang.arrayindexoutofboundsexception: 25 Peale try/catch blokki. 15

16 Mitme püünise kasutamine Mitme püünise kasutamise korral tuleb meeles pidada, et erindite alamklassid peavad olema enne ülemklasse. Näiteks järgmine programm annab kompileerimisel vea: class SuperSubCatch { public static void main(string[] args) { try { int a = 0; int b = 42 / a; catch(exception e) { System.out.println("Üldisem erind."); catch(arithmeticexception e) { System.out.println("Seda erindit ei täideta kunagi"); Arutelu. Mõned küsimused. 16

17 Üksteisesse sisestatud katsendidirektiivid (try) Kui sisemises try blokis tekib erind ja sobivat püünist ei leita, siis otsitakse püünist teda sisaldavast try blokist. Otsing jätkub kuni sobiva leidmiseni või kuni katsendidirektiivide lõppemiseni. class NestTry { public static void main(string[] args) { try { int a = args.length; int b = 20 / a; System.out.println("a = " + a); try { if(a == 1) a = a/(a - a); if(a == 2) { int c[] = { 1 ; c[25] = 100; //sisemine try catch(arrayindexoutofboundsexception e) { System.out.println("Massiivi indeks vigane: " + e); //välimine try catch(arithmeticexception e) { System.out.println("Jagamine nulliga: " + e); >java NestTry Jagamine nulliga: java.lang.arithmeticexception: / by zero >java NestTry 1 a = 1 Jagamine nulliga: java.lang.arithmeticexception: / by zero 17 >java NestTry 1 2 a = 2 Massiivi indeks vigane: java.lang.arrayindexoutofbounds Exception: 25

18 Püünise otsimine kui katsendidirektiivis on meetodi poole pöördumine 18

19 throw - erindi tekitamine Programmis on võimalik erindit ka ise tekitada, kasutades lauset: throw ThrowableInstance; Siin ThrowableInstance peab olema tüüpi Throwable või klassi Throwable alamklass. Järgmisi käske ei täideta ja otsitakse sobivat püünist. class ThrowDemo { static void erindiviskaja() { try { throw new NullPointerException("demo"); catch(nullpointerexception e) { System.out.println("Erind on püütud ja tekitatakse uuesti."); throw e; public static void main(string[] args) { try { erindiviskaja(); catch(nullpointerexception e) { System.out.println("Erind on uuesti kinni püütud: " + e); Erind on kinni püütud ja tekitatakse uuesti. Erind on uuesti kinni püütud: java.lang.nullpointerexception: demo 19

20 throws Kui meetodis on võimalik, et tekib erind (välja arvatud erindid Error või RuntimeException või nende alamklassid), mida ei töödelda, siis tuleb sellest märku anda tema väljakutsujatele võtmesõna throws abil. Meetodi üldkuju: tüüp meetodi-nimi(parameetrite loetelu) throws erindite loetelu { // meetodi keha class ThrowsDemo { static void viskaerind() throws IllegalAccessException { System.out.println(" Meetodi viskaerind sees."); throw new IllegalAccessException("demo"); public static void main(string[] args) { try { viskaerind(); catch (IllegalAccessException e) { System.out.println("Püütud erind: " + e); Meetodi viskaerind sees. Püütud erind: java.lang.illegalaccessexception: demo 20

21 Oma erindiklassi loomine Selleks tuleb defineerida klassi Exception alamklass. Saab kasutada (ja üle katta) meetodeid, mis on päritud klassist Throwable. String getmessage( ) - tagastab erindi kirjelduse; void printstacktrace( ) - näitab, kust erind tuli (magasini sisu); Throwable fillinstacktrace( ) - tagastab objekti Throwable, mis sisaldab magasini; StackTraceElement[ ] getstacktrace( ) tagastab massiivi magasinielementidest; 21

22 class MinuErind extends Exception { private int detail; MinuErind(int a) { detail = a; public String tostring() { return "MinuErind[" + detail + "]"; 22

23 class ExceptionDemo { static void compute(int a) throws MinuErind { System.out.println("Kutsuti välja compute(" + a + ")"); if(a > 10){ throw new MinuErind(a); System.out.println("Normaalne lõpp"); public static void main(string args[]) { try { compute(1); compute(20); catch (MinuErind e) { System.out.println("Püüti " + e); Kutsuti välja compute(1) Normaalne lõpp Kutsuti välja compute(20) Püüti MinuErind[20] 23

24 finally Ei ole kohustuslik Kuid: iga katsendidirektiiv (try) nõuab vähemalt ühte catch blokki või bloki finally olemasolu class FinallyDemo { public static void main(string args[]) { try { meetod1(); catch (Exception e) { System.out.println("Püüti erind"); meetod2(); meetod3(); 24

25 static void meetod1() { try { System.out.println("meetod1 sees"); throw new RuntimeException("demo"); finally { System.out.println("meetod1 finally"); static void meetod2() { try { System.out.println("meetod2 sees"); return; finally { System.out.println("meetod2 finally"); static void meetod3() { try { System.out.println("meetod3 sees"); finally { System.out.println("meetod3 finally"); meetod1 sees meetod1 finally Püüti erind meetod2 sees meetod2 finally meetod3 sees meetod3 finally 25

26 Aheldatud erindid (chained exceptions) Mõnikord on vaja erindi töötlemisel tekitada uus erind, mis annab esialgse erindi kohta täiendavat informatsiooni. Niisuguseid erindeid nimetatakse aheldatud erinditeks. Aheldatud erindi realiseerimiseks saab kasutada klassi Throwable kahte konstruktorit Throwable(Throwable causeexc) Throwable(String msg, Throwable causeexc) ja kahte meetodit: Throwable getcause( ) tagastab jooksva erindi Throwable initcause(throwable causeexc) tagastab põhjustava erindi 26

27 1 public class ChainedExceptionDemo { 2 public static void main(string[] args) { 3 try { 4 meetod1(); 5 6 catch (Exception ex) { 7 ex.printstacktrace(); 8 public static void meetod1() throws Exception { 9 try { 10 meetod2(); catch (Exception ex) { 13 throw new Exception("Uus info meetod1-st", ex); 14 public static void meetod2() throws Exception { 15 throw new Exception("Uus info meetod2-st"); java.lang.exception: Uus info meetod1-st at ChainedExceptionDemo.meetod1(ChainedExceptionDemo.java:13) at ChainedExceptionDemo.main(ChainedExceptionDemo.java:4) Caused by: java.lang.exception: Uus info meetod2-st at ChainedExceptionDemo.meetod2(ChainedExceptionDemo.java:15) at ChainedExceptionDemo.meetod1(ChainedExceptionDemo.java:10) 27

28 Tõend (assertion) Programmi loomise käigus on võimalik luua tõend, millele vastav tingimus peab olema tõene programmi kogu töö vältel. Seda saab teha võtmesõna assert abil kahel viisil: assert condition; või assert condition : expr; public class AssertionDemo { public static void main(string[] args) { int i; int sum = 0; for (i = 0; i < 10; i++) { sum += i; assert i == 10; assert sum > 100 : "summa on " + sum; >java ea AssertionDemo Tõendi sisselülitamine 28

29 Probleemid erindite töötlemisel try-blokis defineeritud objekte ei saa väljaspool (näiteks püünistes) kasutada, sest kompilaatori arvates ei ole neid olemas (ei ole garanteeritud juhtimise jõudmine nende kirjeldusteni). Java ei võimalda katkestuskohast jätkamist. Kui soovitakse sellist efekti saavutada, tuleb katsendidirektiiv panna mingi tsükli mõjupiirkonda. Isetehtud erindite korral tuleks hoolitseda konstruktorite eest, kuna ainult vaikekonstruktorist ei piisa: class MinuErind extends Exception { public MinuErind () { super(); public MinuErind (String s) { super (s); 29

30 Erindite töötlemise eelised 1. Vigu töötleva koodi ja tavalise koodi eraldamine lugedafail { avada fail; määrata faili suurus; eraldada mälu; lugeda fail mällu; sulgeda fail; Mis juhtub, kui faili ei õnnestu avada? faili suurust ei õnnestu määrata? ei õnnestu eraldada mälu? faili lugemine ebaõnnestub? faili ei õnnestu sulgeda? 30

31 Pseudokood ilma erinditeta lugedafail_veatootlusega { veakood = 0; avada fail; if (fail avatud) { määrata faili pikkus; if (pikkusmääratud) { eraldada mälu; if (mälu eraldatud) { lugeda fail mällu; if (lugemine ei õnnestunud) { veakood = -1; else { veakood = -2; else { veakood = -3; sulgeda fail; if (sulgemine ebaõnnestus && veakood == 0) { veakood = -4; else { veakood = -5; else { veakood = -6; return veakood; 31

32 Pseudokood - erindid lugedafail { try { avada fail; määrata faili suurus; eraldada mälu; lugeda fail mällu; sulgeda fail; catch (faili avamine ebaõnnestus) { teemidagi; catch (suuruse määramine ebaõnnestus) { teemidagi; catch (mälu eraldamine ebaünnestus) { teemidagi; catch (lugemine ebaõnnestus) { teemidagi; catch (faili sulgemine ebaõnnestus) { teemidagi; 32

33 2. Vigade töötlemise edasiandmine magasini abil method1 { call method2; method2 { call method3; method3 { call lugedafail; Oletame, et ainult method1 on huvitatud vigadest faili lugemisel 33

34 Pseudokood ilma erinditeta method1 { error = call method2; if (error) doerrorprocessing; else proceed; errorcodetype method2 { error = call method3; if (error) return error; else proceed; errorcodetype method3 { error = call lugedafail; if (error) return error; else proceed; 34

35 method1 { try { call method2; catch (exception) { doerrorprocessing; method2 throws exception { call method3; method3 throws exception { call lugedafail; Pseudokood - erindid 35

36 Iseseisvalt: 1. Y. Daniel Liang Introduction to Java programming fifth ed. Ch. 15 või sixth ed. Ch. 17 Lesson aadressilt või Chapter 8 punktid 1-4 aadressilt 36

Objektorienteeritud programmeerimine

Objektorienteeritud programmeerimine Objektorienteeritud programmeerimine 10. loeng 15. aprill Eno Tõnisson 1 Kasutatud H. Heina loengumaterjalid J. Kiho Väike Java leksikon J. Kiho Java Programmeerimise aabits Y. D. Liang Introduction to

More information

Puudub protseduur. Protseduuri nimi võib olla valesti kirjutatud. Protseduuri (või funktsiooni) poole pöördumisel on vähem argumente kui vaja.

Puudub protseduur. Protseduuri nimi võib olla valesti kirjutatud. Protseduuri (või funktsiooni) poole pöördumisel on vähem argumente kui vaja. Puudub protseduur. Protseduuri nimi võib olla valesti kirjutatud. Sub prog1() Msgox "Tere" Sub prog2() a = si(1) Protseduuri (või funktsiooni) poole pöördumisel on vähem argumente kui vaja. a = Sin() Protseduuri

More information

Objektorienteeritud programmeerimine

Objektorienteeritud programmeerimine Objektorienteeritud programmeerimine 10. loeng 9. aprill Eno Tõnisson 1 Kasutatud H. Heina loengumaterjalid J. Kiho Väike Java leksikon J. Kiho Java Programmeerimise aabits Y. D. Liang Introduction to

More information

CSC 1214: Object-Oriented Programming

CSC 1214: Object-Oriented Programming CSC 1214: Object-Oriented Programming J. Kizito Makerere University e-mail: jkizito@cis.mak.ac.ug www: http://serval.ug/~jona materials: http://serval.ug/~jona/materials/csc1214 e-learning environment:

More information

Unit 4. Exception handling mechanism. new look try/catch mechanism in Java Enumeration in Java 5 - usage.

Unit 4. Exception handling mechanism. new look try/catch mechanism in Java Enumeration in Java 5 - usage. Unit 4 Exception handling mechanism. new look try/catch mechanism in Java Enumeration in Java 5 - usage. exceptions An exception is an abnormal condition that arises in a code sequence at run time. an

More information

Objektorienteeritud programmeerimine

Objektorienteeritud programmeerimine Objektorienteeritud programmeerimine 11. loeng, 23. aprill Marina Lepp 1 Eelmisel nädalal Loeng vood, erindid 1. kontrolltöö järeltöö Praktikum vood Ülemaailmne maapäev (22.04) 2 Umbes mitu tundi tegelesite

More information

Introduction. Exceptions: An OO Way for Handling Errors. Common Runtime Errors. Error Handling. Without Error Handling Example 1

Introduction. Exceptions: An OO Way for Handling Errors. Common Runtime Errors. Error Handling. Without Error Handling Example 1 Exceptions: An OO Way for Handling Errors Introduction Rarely does a program runs successfully at its very first attempt. It is common to make mistakes while developing as well as typing a program. Such

More information

Unit III Exception Handling and I/O Exceptions-exception hierarchy-throwing and catching exceptions-built-in exceptions, creating own exceptions, Stack Trace Elements. Input /Output Basics-Streams-Byte

More information

Java Programming MCA 205 Unit - II. Learning Objectives. Introduction. 7/31/2013MCA-205 Java Programming

Java Programming MCA 205 Unit - II. Learning Objectives. Introduction. 7/31/2013MCA-205 Java Programming Java Programming MCA 205 Unit - II UII. Learning Objectives Exception Handling: Fundamentals exception types, uncaught exceptions, throw, throw, final, built in exception, creating your own exceptions,

More information

Le L c e t c ur u e e 5 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Exception Handling

Le L c e t c ur u e e 5 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Exception Handling Course Name: Advanced Java Lecture 5 Topics to be covered Exception Handling Exception HandlingHandlingIntroduction An exception is an abnormal condition that arises in a code sequence at run time A Java

More information

Mis on tõene? Tsüklid, failihaldus. if - näited. unless - näited. unless. Merle Sibola. if ($arv > $suur) { #leitakse suurim arv $suur=$arv; } #if

Mis on tõene? Tsüklid, failihaldus. if - näited. unless - näited. unless. Merle Sibola. if ($arv > $suur) { #leitakse suurim arv $suur=$arv; } #if Mis on tõene? Tsüklid, failihaldus Merle Sibola iga string on tõene, välja arvatud "" ja "0" iga number on tõene, v.a. number 0 Iga viide (reference) on tõene Iga defineerimata muutuja on väär. if if (EXPR)

More information

Exceptions, try - catch - finally, throws keyword. JAVA Standard Edition

Exceptions, try - catch - finally, throws keyword. JAVA Standard Edition Exceptions, try - catch - finally, throws keyword JAVA Standard Edition Java - Exceptions An exception (or exceptional event) is a problem that arises during the execution of a program. When an Exception

More information

Inheritance. Inheritance allows re-usability of the code. In Java, we use the terminology as super class and sub class.

Inheritance. Inheritance allows re-usability of the code. In Java, we use the terminology as super class and sub class. Inheritance Inheritance allows re-usability of the code. In Java, we use the terminology as super class and sub class. Inheritance is achieved using the keyword extends. Java does not support multiple

More information

Vea haldus ja logiraamat hajutatud süsteemides Enn Õunapuu.

Vea haldus ja logiraamat hajutatud süsteemides Enn Õunapuu. Vea haldus ja logiraamat hajutatud süsteemides Enn Õunapuu enn.ounapuu@ttu.ee Millest tuleb jutt? Kuidas ma näen, millises sammus erinevad protsessid parasjagu on? Kuidas ma aru saan, kas protsess töötab

More information

SQL Server 2005 Expressi paigaldamine

SQL Server 2005 Expressi paigaldamine SQL Server 2005 Expressi paigaldamine Laadige alla.net Framework 2.0 http://www.microsoft.com/downloads/details.aspx?familyid=0856eacb-4362-4b0d- 8edd-aab15c5e04f5 Avage http://www.microsoft.com/express/2005/sql/download/default.aspx

More information

Objekt-orienteeritud programmeerimine MTAT (6 EAP) 5. Loeng. H e l l e H e i n h e l l e. h e i e e

Objekt-orienteeritud programmeerimine MTAT (6 EAP) 5. Loeng. H e l l e H e i n h e l l e. h e i e e Objekt-orienteeritud programmeerimine MTAT.03.130 (6 EAP) 5. Loeng H e l l e H e i n h e l l e. h e i n @ut. e e Täna loengus: Abstraktsed klassid Liidesed Mähisklassid 2 Abstraktsed klassid Meetodit nimetatakse

More information

More on Exception Handling

More on Exception Handling Chapter 18 More on Exception Handling Lecture slides for: Java Actually: A Comprehensive Primer in Programming Khalid Azim Mughal, Torill Hamre, Rolf W. Rasmussen Cengage Learning, 2008. ISBN: 978-1-844480-933-2

More information

BBM 102 Introduction to Programming II Spring Exceptions

BBM 102 Introduction to Programming II Spring Exceptions BBM 102 Introduction to Programming II Spring 2018 Exceptions 1 Today What is an exception? What is exception handling? Keywords of exception handling try catch finally Throwing exceptions throw Custom

More information

C16b: Exception Handling

C16b: Exception Handling CISC 3120 C16b: Exception Handling Hui Chen Department of Computer & Information Science CUNY Brooklyn College 3/28/2018 CUNY Brooklyn College 1 Outline Exceptions Catch and handle exceptions (try/catch)

More information

MSDE Upgrade platvormile SQL 2005 Server Express SP4

MSDE Upgrade platvormile SQL 2005 Server Express SP4 MSDE Upgrade platvormile SQL 2005 Server Express SP4 NB! Windos XP puhul peab veenduma, et masinas oleks paigaldatud.net Framework vähemalt versioon 2.0!!! NB! Muutke oma SA parool turvaliseks ( minimaalne

More information

Objektorienteeritud programmeerimine

Objektorienteeritud programmeerimine Objektorienteeritud programmeerimine 10. loeng, 16. aprill Marina Lepp 1 Eelmisel nädalal Loeng vood Lisapraktikum Praktikum sündmused Künnipäev (12.04) 2 Umbes mitu tundi tegelesite eelmisel nädalal selle

More information

Programmeerimine. 3. loeng

Programmeerimine. 3. loeng Programmeerimine 3. loeng Tana loengus T~oevaartustuup ja loogilised avaldised Hargnemisdirektiivid { Lihtne if-lause { if-else-lause { Uldkujuline if-lause Tsuklidirektiivid { Eelkontrolliga tsukkel {

More information

More on Exception Handling

More on Exception Handling Chapter 18 More on Exception Handling Lecture slides for: Java Actually: A Comprehensive Primer in Programming Khalid Azim Mughal, Torill Hamre, Rolf W. Rasmussen Cengage Learning, 2008. ISBN: 978-1-844480-933-2

More information

What are Exceptions?

What are Exceptions? Exception Handling What are Exceptions? The traditional approach Exception handing in Java Standard exceptions in Java Multiple catch handlers Catching multiple exceptions finally block Checked vs unchecked

More information

BBM 102 Introduction to Programming II Spring 2017

BBM 102 Introduction to Programming II Spring 2017 BBM 102 Introduction to Programming II Spring 2017 Exceptions Instructors: Ayça Tarhan, Fuat Akal, Gönenç Ercan, Vahid Garousi Today What is an exception? What is exception handling? Keywords of exception

More information

Exception-Handling try catch throw throws finally try try catch throw throws finally

Exception-Handling try catch throw throws finally try try catch throw throws finally Exception-Handling A Java exception is an object that describes an exceptional (that is, error) condition that has occurred in a piece of code. When an exceptional condition arises, an object representing

More information

Exceptions: When something goes wrong. Image from Wikipedia

Exceptions: When something goes wrong. Image from Wikipedia Exceptions: When something goes wrong Image from Wikipedia Conditions that cause exceptions > Error internal to the Java Virtual Machine > Standard exceptions: Divide by zero Array index out of bounds

More information

2- Runtime exception: UnChecked (execution of program) automatically propagated in java. don t have to throw, you can but isn t necessary

2- Runtime exception: UnChecked (execution of program) automatically propagated in java. don t have to throw, you can but isn t necessary EXCEPTIONS... 3 3 categories of exceptions:...3 1- Checked exception: thrown at the time of compilation....3 2- Runtime exception: UnChecked (execution of program) automatically propagated in java. don

More information

XmlHttpRequest asemel võib olla vajalik objekt XDomainRequest

XmlHttpRequest asemel võib olla vajalik objekt XDomainRequest 1 2 3 XmlHttpRequest asemel võib olla vajalik objekt XDomainRequest 4 5 6 7 8 https://www.trustwave.com/global-security-report http://redmondmag.com/articles/2012/03/12/user-password-not-sophisticated.aspx

More information

Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 7

Object oriented programming. Instructor: Masoud Asghari Web page:   Ch: 7 Object oriented programming Instructor: Masoud Asghari Web page: http://www.masses.ir/lectures/oops2017sut Ch: 7 1 In this slide We follow: https://docs.oracle.com/javase/tutorial/index.html Trail: Essential

More information

Exceptions. References. Exceptions. Exceptional Conditions. CSE 413, Autumn 2005 Programming Languages

Exceptions. References. Exceptions. Exceptional Conditions. CSE 413, Autumn 2005 Programming Languages References Exceptions "Handling Errors with Exceptions", Java tutorial http://java.sun.com/docs/books/tutorial/essential/exceptions/index.html CSE 413, Autumn 2005 Programming Languages http://www.cs.washington.edu/education/courses/413/05au/

More information

13: Error Handling with Exceptions. The basic philosophy of Java is that "badly formed code will not be run."

13: Error Handling with Exceptions. The basic philosophy of Java is that badly formed code will not be run. 13: Error Handling with Exceptions The basic philosophy of Java is that "badly formed code will not be run." 1 Error Handling in Java C++/Java: Badly-formed code will not compile. Java: Badly-formed code,

More information

ITI Introduction to Computing II

ITI Introduction to Computing II ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Version of February 23, 2013 Abstract Handling errors Declaring, creating and handling exceptions

More information

ITI Introduction to Computing II

ITI Introduction to Computing II ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Version of February 23, 2013 Abstract Handling errors Declaring, creating and handling exceptions

More information

EXCEPTION-HANDLING INTRIVIEW QUESTIONS

EXCEPTION-HANDLING INTRIVIEW QUESTIONS EXCEPTION-HANDLING INTRIVIEW QUESTIONS Q1.What is an Exception? Ans.An unwanted, unexpected event that disturbs normal flow of the program is called Exception.Example: FileNotFondException. Q2.What is

More information

exceptions catch (ArithmeticException exc) { // catch the exception System.out.println("Can't divide by Zero!");

exceptions catch (ArithmeticException exc) { // catch the exception System.out.println(Can't divide by Zero!); s // Subclasses must precede superclasses in catch statements. class ExcDemo5 { // Here, numer is longer than denom. int numer[] = { 4, 8, 16, 32, 64, 128, 256, 512 ; int denom[] = { 2, 0, 4, 4, 0, 8 ;

More information

UNIT - V. Inheritance Interfaces and inner classes Exception handling Threads Streams and I/O

UNIT - V. Inheritance Interfaces and inner classes Exception handling Threads Streams and I/O UNIT - V Inheritance Interfaces and inner classes Exception handling Threads Streams and I/O 1 INHERITANCE 2 INHERITANCE What is Inheritance? Inheritance is the mechanism which allows a class B to inherit

More information

Software Practice 1 - Error Handling

Software Practice 1 - Error Handling Software Practice 1 - Error Handling Exception Exception Hierarchy Catching Exception Userdefined Exception Practice#5 Prof. Joonwon Lee T.A. Jaehyun Song Jongseok Kim (42) T.A. Sujin Oh Junseong Lee 1

More information

COMP200 EXCEPTIONS. OOP using Java, based on slides by Shayan Javed

COMP200 EXCEPTIONS. OOP using Java, based on slides by Shayan Javed 1 1 COMP200 EXCEPTIONS OOP using Java, based on slides by Shayan Javed Exception Handling 2 3 Errors Syntax Errors Logic Errors Runtime Errors 4 Syntax Errors Arise because language rules weren t followed.

More information

Exceptions. CSE 142, Summer 2002 Computer Programming 1.

Exceptions. CSE 142, Summer 2002 Computer Programming 1. Exceptions CSE 142, Summer 2002 Computer Programming 1 http://www.cs.washington.edu/education/courses/142/02su/ 12-Aug-2002 cse142-19-exceptions 2002 University of Washington 1 Reading Readings and References»

More information

Exceptions. Readings and References. Exceptions. Exceptional Conditions. Reading. CSE 142, Summer 2002 Computer Programming 1.

Exceptions. Readings and References. Exceptions. Exceptional Conditions. Reading. CSE 142, Summer 2002 Computer Programming 1. Readings and References Exceptions CSE 142, Summer 2002 Computer Programming 1 http://www.cs.washington.edu/education/courses/142/02su/ Reading» Chapter 18, An Introduction to Programming and Object Oriented

More information

Unit 5 - Exception Handling & Multithreaded

Unit 5 - Exception Handling & Multithreaded Exceptions Handling An exception (or exceptional event) is a problem that arises during the execution of a program. When an Exception occurs the normal flow of the program is disrupted and the program/application

More information

we dont take any liability for the notes correctness.

we dont take any liability for the notes correctness. 1 Unit 3 Topic:Multithreading and Exception Handling Unit 3/Lecture 1 MultiThreading [RGPV/June 2011(10)] Unlike many other computer languages, Java provides built-in support for multithreaded programming.

More information

Recitation 3. 2D Arrays, Exceptions

Recitation 3. 2D Arrays, Exceptions Recitation 3 2D Arrays, Exceptions 2D arrays 2D Arrays Many applications have multidimensional structures: Matrix operations Collection of lists Board games (Chess, Checkers) Images (rows and columns of

More information

CS115. Chapter 17 Exception Handling. Prof. Joe X. Zhou Department of Computer Science. To know what is exception and what is exception handling

CS115. Chapter 17 Exception Handling. Prof. Joe X. Zhou Department of Computer Science. To know what is exception and what is exception handling CS115 Pi Principles i of fcomputer Science Chapter 17 Exception Handling Prof. Joe X. Zhou Department of Computer Science CS115 ExceptionHandling.1 Objectives in Exception Handling To know what is exception

More information

Digitaalne signaal Diskreetimine ja Dirac Delta Digitaalfiltrid. Digitaalne heli. Hendrik Nigul. Mathematics of Sound and Music.

Digitaalne signaal Diskreetimine ja Dirac Delta Digitaalfiltrid. Digitaalne heli. Hendrik Nigul. Mathematics of Sound and Music. Mathematics of Sound and Music Aprill 2007 Outline 1 Digitaalne signaal 2 3 z-teisendus Mis on heli? Digitaalne signaal Heli on elastses keskkonnas lainena leviv mehaaniline võnkumine. amplituud heli tugevus

More information

A Third Look At Java. Chapter Seventeen Modern Programming Languages, 2nd ed. 1

A Third Look At Java. Chapter Seventeen Modern Programming Languages, 2nd ed. 1 A Third Look At Java Chapter Seventeen Modern Programming Languages, 2nd ed. 1 A Little Demo public class Test { public static void main(string[] args) { int i = Integer.parseInt(args[0]); int j = Integer.parseInt(args[1]);

More information

Exception Handling. --After creating exception object,method handover that object to the JVM.

Exception Handling. --After creating exception object,method handover that object to the JVM. Exception Handling 1. Introduction 2. Runtime Stack Mechanism 3. Default Exception Handling in Java 4. Exception Hirarchy 5. Customized Exception Handling By using -catch 6. Control flow in -catch 7. Methods

More information

Exceptions - Example. Exceptions - Example

Exceptions - Example. Exceptions - Example - Example //precondition: x >= 0 public void sqrt(double x) double root; if (x < 0.0) //What to do? else //compute the square root of x return root; 1 - Example //precondition: x >= 0 public void sqrt(double

More information

TP-Link TL-WR743ND Juhend

TP-Link TL-WR743ND Juhend TP-Link TL-WR743ND Juhend 1) Ühenda oma arvuti TP-Link ruuteriga üle kaabli (LAN). 2) Kui arvuti ja ruuter said omavahel ühendatud, siis võid minna seadme koduleheküljele (interneti brauseri otsingu reasse

More information

Mälu interfeisid Arvutikomponendid Ergo Nõmmiste

Mälu interfeisid Arvutikomponendid Ergo Nõmmiste Mälu interfeisid Arvutikomponendid Ergo Nõmmiste Mälu liigid Read-only memory (ROM) Flash memory (EEPROM) Static random access memory (SRAM) Dynamic random access memoty (DRAM) 1 kbaidine mälu vajab 10

More information

Here is a hierarchy of classes to deal with Input and Output streams.

Here is a hierarchy of classes to deal with Input and Output streams. PART 15 15. Files and I/O 15.1 Reading and Writing Files A stream can be defined as a sequence of data. The InputStream is used to read data from a source and the OutputStream is used for writing data

More information

Exceptions. CSC207 Winter 2017

Exceptions. CSC207 Winter 2017 Exceptions CSC207 Winter 2017 What are exceptions? In Java, an exception is an object. Exceptions represent exceptional conditions: unusual, strange, disturbing. These conditions deserve exceptional treatment:

More information

6.Introducing Classes 9. Exceptions

6.Introducing Classes 9. Exceptions 6.Introducing Classes 9. Exceptions Sisoft Technologies Pvt Ltd SRC E7, Shipra Riviera Bazar, Gyan Khand-3, Indirapuram, Ghaziabad Website: www.sisoft.in Email:info@sisoft.in Phone: +91-9999-283-283 Learning

More information

Day 8. COMP1006/1406 Summer M. Jason Hinek Carleton University

Day 8. COMP1006/1406 Summer M. Jason Hinek Carleton University Day 8 COMP1006/1406 Summer 2016 M. Jason Hinek Carleton University today s agenda assignments Assignment 4 is out and due on Tuesday Bugs and Exception handling 2 Bugs... often use the word bug when there

More information

Exception-Handling Overview

Exception-Handling Overview م.عبد الغني أبوجبل Exception Handling No matter how good a programmer you are, you cannot control everything. Things can go wrong. Very wrong. When you write a risky method, you need code to handle the

More information

WD My Net N600 juhend:

WD My Net N600 juhend: WD My Net N600 juhend: 1) Kui WD My Net N600 seade on ühendatud näiteks Elioni Thomsoni ruuteriga (TG789vn või TG784) või Elioni Inteno DG301a ruuteriga, kus üldiselt on ruuteri Default Gateway sama, nagu

More information

CSC207H: Software Design. Exceptions. CSC207 Winter 2018

CSC207H: Software Design. Exceptions. CSC207 Winter 2018 Exceptions CSC207 Winter 2018 1 What are exceptions? Exceptions represent exceptional conditions: unusual, strange, disturbing. These conditions deserve exceptional treatment: not the usual go-tothe-next-step,

More information

Java Programming Language Mr.Rungrote Phonkam

Java Programming Language Mr.Rungrote Phonkam 9 Java Programming Language Mr.Rungrote Phonkam rungrote@it.kmitl.ac.th Contents 1 Exception Handling 1.1. Implicitly Exception 1.2. Explicitly Exception 2. Handle Exception 3. Threads 1 Exception Handling

More information

Chapter 12 Exception Handling

Chapter 12 Exception Handling Chapter 12 Exception Handling 1 Motivations Goal: Robust code. When a program runs into a runtime error, the program terminates abnormally. How can you handle the runtime error so that the program can

More information

CS 200 Command-Line Arguments & Exceptions Jim Williams, PhD

CS 200 Command-Line Arguments & Exceptions Jim Williams, PhD CS 200 Command-Line Arguments & Exceptions Jim Williams, PhD This Week 1. Battleship: Milestone 3 a. First impressions matter! b. Comment and style 2. Team Lab: ArrayLists 3. BP2, Milestone 1 next Wednesday

More information

Chapter 13 Exception Handling

Chapter 13 Exception Handling Chapter 13 Exception Handling 1 Motivations When a program runs into a runtime error, the program terminates abnormally. How can you handle the runtime error so that the program can continue to run or

More information

Andmebaasi krüpteerimine ja dekrüpteerimine

Andmebaasi krüpteerimine ja dekrüpteerimine Andmebaasi krüpteerimine ja dekrüpteerimine Me võime küll asetanud kõikidele andmebaasi objektidele ligipääsuõigused eri kasutajate jaoks, kuid ikkagi võib mõni häkker avada vastava faili lihtsalt failina

More information

Ülesannete tüüpide tutvustus! a kevad

Ülesannete tüüpide tutvustus! a kevad Ülesannete tüüpide tutvustus! Võimalike teemade ring hõlmab kogu kursust!!! 2018. a kevad Tegelikult on eksamitöös 4 ülesannet Ülesanne 1 (? punkti) Võib eeldada, et vajalikud asjad on imporditud ja klassi

More information

Object Oriented Programming

Object Oriented Programming Object Oriented Programming Java lecture (10.2) Exception Handling 1 Outline Throw Throws Finally 2 Throw we have only been catching exceptions that are thrown by the Java run-time system. However, it

More information

CSCI 261 Computer Science II

CSCI 261 Computer Science II CSCI 261 Computer Science II Department of Mathematics and Computer Science Lecture 2 Exception Handling New Topic: Exceptions in Java You should now be familiar with: Advanced object-oriented design -

More information

Exception Handling in Java

Exception Handling in Java Exception Handling in Java The exception handling is one of the powerful mechanism provided in java. It provides the mechanism to handle the runtime errors so that normal flow of the application can be

More information

Tsüklidirektiivid. Klass Math. Staatilised meetodid. Massiivid. Koostada programm, mis leiab positiivsete paarisarvude summat vahemikus 1 kuni 20.

Tsüklidirektiivid. Klass Math. Staatilised meetodid. Massiivid. Koostada programm, mis leiab positiivsete paarisarvude summat vahemikus 1 kuni 20. Harjutustund 3 Tsüklidirektiivid. Klass Math. Staatilised meetodid. Massiivid. Tsüklidirektiivid Vaadake teooriat eelmisest praktikumist. Ülesanne 1 Koostada programm, mis leiab esimeste 20 arvude summat

More information

NAS, IP-SAN, CAS. Loeng 4

NAS, IP-SAN, CAS. Loeng 4 NAS, IP-SAN, CAS Loeng 4 Tunniteemad Network Attached Storage IP Storage Attached Network Content Addressed Storage Network Attached Storage Tehnoloogia, kus andmed on jagatud üle võrgu Salvestusvahendile

More information

A problem?... Exceptions. A problem?... A problem?... Suggested Reading: Bruce Eckel, Thinking in Java (Fourth Edition) Error Handling with Exceptions

A problem?... Exceptions. A problem?... A problem?... Suggested Reading: Bruce Eckel, Thinking in Java (Fourth Edition) Error Handling with Exceptions A problem?... Exceptions Suggested Reading: Bruce Eckel, Thinking in Java (Fourth Edition) Error Handling with Exceptions 2 A problem?... A problem?... 3 4 A problem?... A problem?... 5 6 A problem?...

More information

Objektorienteeritud programmeerimine

Objektorienteeritud programmeerimine Objektorienteeritud programmeerimine 2. loeng 19. veebruar 2018 Marina Lepp 1 Möödunud nädalal Loeng Sissejuhatus Praktikum Paaristöö, algus Vastlapäev Sõbrapäev Hiina uusaasta 2 Umbes mitu tundi tegelesite

More information

Exceptions Questions https://www.journaldev.com/2167/java-exception-interview-questionsand-answers https://www.baeldung.com/java-exceptions-interview-questions https://javaconceptoftheday.com/java-exception-handling-interviewquestions-and-answers/

More information

Administration. Exceptions. Leftovers. Agenda. When Things Go Wrong. Handling Errors. CS 99 Summer 2000 Michael Clarkson Lecture 11

Administration. Exceptions. Leftovers. Agenda. When Things Go Wrong. Handling Errors. CS 99 Summer 2000 Michael Clarkson Lecture 11 Administration Exceptions CS 99 Summer 2000 Michael Clarkson Lecture 11 Lab 10 due tomorrow No lab tomorrow Work on final projects Remaining office hours Rick: today 2-3 Michael: Thursday 10-noon, Monday

More information

Full file at Chapter 2 - Inheritance and Exception Handling

Full file at   Chapter 2 - Inheritance and Exception Handling Chapter 2 - Inheritance and Exception Handling TRUE/FALSE 1. The superclass inherits all its properties from the subclass. ANS: F PTS: 1 REF: 76 2. Private members of a superclass can be accessed by a

More information

ECE 122. Engineering Problem Solving with Java

ECE 122. Engineering Problem Solving with Java ECE 122 Engineering Problem Solving with Java Lecture 24 Exceptions Overview Problem: Can we detect run-time errors and take corrective action? Try-catch Test for a variety of different program situations

More information

Exception Handling in Java. An Exception is a compile time / runtime error that breaks off the

Exception Handling in Java. An Exception is a compile time / runtime error that breaks off the Description Exception Handling in Java An Exception is a compile time / runtime error that breaks off the program s execution flow. These exceptions are accompanied with a system generated error message.

More information

Software Practice 1 - Error Handling Exception Exception Hierarchy Catching Exception Userdefined Exception Practice#5

Software Practice 1 - Error Handling Exception Exception Hierarchy Catching Exception Userdefined Exception Practice#5 1 Software Practice 1 - Error Handling Exception Exception Hierarchy Catching Exception Userdefined Exception Practice#5 Prof. Hwansoo Han T.A. Jeonghwan Park 41 T.A. Sung-in Hong 42 2 Exception An exception

More information

Exception in thread "main" java.lang.arithmeticexception: / by zero at DefaultExceptionHandling.main(DefaultExceptionHandling.

Exception in thread main java.lang.arithmeticexception: / by zero at DefaultExceptionHandling.main(DefaultExceptionHandling. Exceptions 1 Handling exceptions A program will sometimes inadvertently ask the machine to do something which it cannot reasonably do, such as dividing by zero, or attempting to access a non-existent array

More information

Chapter 12 Exception Handling and Text IO. Liang, Introduction to Java Programming, Tenth Edition, Global Edition. Pearson Education Limited

Chapter 12 Exception Handling and Text IO. Liang, Introduction to Java Programming, Tenth Edition, Global Edition. Pearson Education Limited Chapter 12 Exception Handling and Text IO Liang, Introduction to Java Programming, Tenth Edition, Global Edition. Pearson Education Limited 2015 1 Motivations When a program runs into a runtime error,

More information

Object Oriented Programming

Object Oriented Programming Object Oriented Programming Java lecture (10.1) Exception Handling 1 Outline Exception Handling Mechanisms Exception handling fundamentals Exception Types Uncaught exceptions Try and catch Multiple catch

More information

Tabelid <TABLE> Koostanud: Merike Hein

Tabelid <TABLE> Koostanud: Merike Hein Tabelid Tabelite kasutusvõimalus on HTML'is olemas juba pikka aega. Tabelimärgendite esmaseks kasutusalaks oli muidugi mõista tabelkujul info kuvamine. tähendab siis tabelite joonistamist.

More information

Andmebaasid (6EAP) I praktikum

Andmebaasid (6EAP) I praktikum Andmebaasid (6EAP) I praktikum Mõisteid Server on arvutisüsteem või selles töötav tarkvara, mis pakub teatud infoteenust sellega ühenduvatele klientidele. Klient on tarkvara, mis võimaldab suhelda serveriga.

More information

Download link: Java Exception Handling

Download link:  Java Exception Handling What is an Exception? Java Exception Handling Error that occurs during runtime Exceptional event Cause normal program flow to be disrupted Java Exception Examples 1. Divide by zero errors 2. Accessing

More information

COMP1008 Exceptions. Runtime Error

COMP1008 Exceptions. Runtime Error Runtime Error COMP1008 Exceptions Unexpected error that terminates a program. Undesirable Not detectable by compiler. Caused by: Errors in the program logic. Unexpected failure of services E.g., file server

More information

Lõimed. Lõime mõiste. Lõimede mudelid. Probleemid lõimedega seoses. Pthreads. Solarise lõimed. Windowsi lõimed. FreeBSD lõimed.

Lõimed. Lõime mõiste. Lõimede mudelid. Probleemid lõimedega seoses. Pthreads. Solarise lõimed. Windowsi lõimed. FreeBSD lõimed. Lõimed Lõime mõiste Lõimede mudelid Probleemid lõimedega seoses Pthreads Solarise lõimed Windowsi lõimed FreeBSD lõimed Linuxi lõimed MEELIS ROOS 1 Ühe- ja mitmelõimelised protsessid code data files code

More information

National University. Faculty of Computer Since and Technology Object Oriented Programming

National University. Faculty of Computer Since and Technology Object Oriented Programming National University Faculty of Computer Since and Technology Object Oriented Programming Lec (8) Exceptions in Java Exceptions in Java What is an exception? An exception is an error condition that changes

More information

Fundamentals of Object Oriented Programming

Fundamentals of Object Oriented Programming INDIAN INSTITUTE OF TECHNOLOGY ROORKEE Fundamentals of Object Oriented Programming CSN- 103 Dr. R. Balasubramanian Associate Professor Department of Computer Science and Engineering Indian Institute of

More information

For more details on SUN Certifications, visit

For more details on SUN Certifications, visit Exception Handling For more details on SUN Certifications, visit http://sunjavasnips.blogspot.com/ Q: 01 Given: 11. public static void parse(string str) { 12. try { 13. float f = Float.parseFloat(str);

More information

Kirje. Kirje. Tüpiseeritud fail. CASE-lause. Laiendatud klahvikoodid. 1

Kirje. Kirje. Tüpiseeritud fail. CASE-lause. Laiendatud klahvikoodid. 1 Kirje. Tüpiseeritud fail. CASE-lause. Laiendatud klahvikoodid. 1 Kirje Kirje (record) on struktuurne andmetüüp (nagu massiiv) erinevat tüüpi andmete gruppeerimiseks. Kirje koosneb väljadest (field). Iga

More information

Programming II (CS300)

Programming II (CS300) 1 Programming II (CS300) Chapter 04: Exception Handling MOUNA KACEM mouna@cs.wisc.edu Fall 2018 Creating Classes 2 Introduction Exception Handling Common Exceptions Exceptions with Methods Assertions and

More information

EXCEPTIONS. Objectives. The try and catch Statements. Define exceptions. Use try, catch and finally statements. Describe exception categories

EXCEPTIONS. Objectives. The try and catch Statements. Define exceptions. Use try, catch and finally statements. Describe exception categories Objectives Define exceptions 8 EXCEPTIONS Use try, catch and finally statements Describe exception categories Identify common exceptions Develop programs to handle your own exceptions 271 272 Exceptions

More information

EESTI STANDARD EVS-ISO 11620:2010

EESTI STANDARD EVS-ISO 11620:2010 EESTI STANDARD EVS-ISO INFORMATSIOON JA DOKUMENTATSIOON Raamatukogu tulemusindikaatorid Information and documentation Library performance indicators (ISO 11620:2008) EVS-ISO EESTI STANDARDI EESSÕNA NATIONAL

More information

Unit III Rupali Sherekar 2017

Unit III Rupali Sherekar 2017 Unit III Exceptions An exception is an abnormal condition that arises in a code sequence at run time. In other words, an exception is a run-time error. In computer languages that do not support exception

More information

EXCEPTIONS. Java Programming

EXCEPTIONS. Java Programming 8 EXCEPTIONS 271 Objectives Define exceptions Exceptions 8 Use try, catch and finally statements Describe exception categories Identify common exceptions Develop programs to handle your own exceptions

More information

Lecture 19 Programming Exceptions CSE11 Fall 2013

Lecture 19 Programming Exceptions CSE11 Fall 2013 Lecture 19 Programming Exceptions CSE11 Fall 2013 When Things go Wrong We've seen a number of run time errors Array Index out of Bounds e.g., Exception in thread "main" java.lang.arrayindexoutofboundsexception:

More information

CS Programming I: Exceptions

CS Programming I: Exceptions CS 200 - Programming I: Marc Renault Department of Computer Sciences University of Wisconsin Madison Spring 2018 TopHat Sec 3 (AM) Join Code: 427811 TopHat Sec 4 (PM) Join Code: 165455 Command-Line Arguments

More information

Exception handling in Java. J. Pöial

Exception handling in Java. J. Pöial Exception handling in Java J. Pöial Errors and exceptions Error handling without dedicated tools: return codes, global error states etc. Problem: it is not reasonable (or even possible) to handle each

More information

Exceptions Handling Errors using Exceptions

Exceptions Handling Errors using Exceptions Java Programming in Java Exceptions Handling Errors using Exceptions Exceptions Exception = Exceptional Event Exceptions are: objects, derived from java.lang.throwable. Throwable Objects: Errors (Java

More information

Title. Java Just in Time. John Latham. February 8, February 8, 2018 Java Just in Time - John Latham Page 1(0/0)

Title. Java Just in Time. John Latham. February 8, February 8, 2018 Java Just in Time - John Latham Page 1(0/0) List of Slides 1 Title 2 Chapter 17: Making our own exceptions 3 Chapter aims 4 Section 2: The exception inheritance hierarchy 5 Aim 6 The exception inheritance hierarchy 7 Exception: inheritance hierarchy

More information

Tallinna Ülikooli veebipuhvri teenuse kasutamine väljaspool ülikooli arvutivõrku

Tallinna Ülikooli veebipuhvri teenuse kasutamine väljaspool ülikooli arvutivõrku Tallinna Ülikooli veebipuhvri teenuse kasutamine väljaspool ülikooli arvutivõrku Selleks, et kasutada Tallinna Ülikooli veebipuhvrit väljaspool ülikooli arvutivõrku, tuleb luua ühendus serveriga lin2.tlu.ee

More information