State Instance Variables Procedures Properties Print Statements Println Vs Print Overloading J++
200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where...
Transcript of 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where...
![Page 1: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/1.jpg)
Lecture 9
200 errors found:Error: /U/TestGQ.java:314: compareTo(GQueue<java.lang.Integer>) inGQueue<java.lang.Integer> cannot be applied to (GQueue<java.lang.String>)...
Summer 2013
M. Jason HinekCarleton University
![Page 2: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/2.jpg)
Day 9
· a quick look back (day 8)
· assignments
· exceptions and exception handling
· throws· try and catch· finally· throw· read Chapter 9 in the Lanthier notes
· a quick look ahead (day 10)
2 / 28
![Page 3: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/3.jpg)
Reminders
Notesif you have been taking (good) notes so far...
get some recognition from the University...
help out a fellow student... email
[email protected] with your name, studentnumber and course code
Final ExamAugust 19, 201319:00
3 / 28
![Page 4: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/4.jpg)
Last time...
The material in Day 8 touched on
· truth and lies about compareTo()
· generics· the ? woldcard for types· restricting types
· wrapper classes· one corresponding to each primitive data type
· method chaining· good or bad?
4 / 28
![Page 5: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/5.jpg)
Bugs...
often use the word bug when there is a problem with our program
· bug is an error in our code (or hardware)
· debugging is a methodical process of �nding and reducing thenumber of bugs
5 / 28
![Page 6: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/6.jpg)
Bugs...
· bug is an error in our code (or hardware)
· debugging is a methodical process of �nding and reducing thenumber of bugs
5 / 28
![Page 7: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/7.jpg)
Bugs...
· bug is an error in our code (or hardware)
· debugging is a methodical process of �nding and reducing thenumber of bugs
5 / 28
![Page 8: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/8.jpg)
Bugs...
· bug is an error in our code (or hardware)
· debugging is a methodical process of �nding and reducing thenumber of bugs
5 / 28
![Page 9: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/9.jpg)
Bugs...
essentially 3 types of bugs/errors
· compile errors
· program does not compile but compiler tells you why· syntax errors, type mismatch errors, ...· these are your fault
· runtime errors
· cannot be determined at compile time· sometimes require re-design of code· these may be your fault
· logical errors
· non-syntax mistakes in your code· Java cannot detect and explain these errors· may be very hard to �nd...· these are definitely your fault
6 / 28
![Page 10: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/10.jpg)
Bugs...
essentially 3 types of bugs/errors
· compile errors
· program does not compile but compiler tells you why· syntax errors, type mismatch errors, ...· these are your fault
· runtime errors
· cannot be determined at compile time· sometimes require re-design of code· these may be your fault
· logical errors
· non-syntax mistakes in your code· Java cannot detect and explain these errors· may be very hard to �nd...· these are definitely your fault
6 / 28
![Page 11: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/11.jpg)
Bugs...
essentially 3 types of bugs/errors
· compile errors
· program does not compile but compiler tells you why· syntax errors, type mismatch errors, ...
· these are your fault
· runtime errors
· cannot be determined at compile time· sometimes require re-design of code· these may be your fault
· logical errors
· non-syntax mistakes in your code· Java cannot detect and explain these errors· may be very hard to �nd...· these are definitely your fault
6 / 28
![Page 12: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/12.jpg)
Bugs...
essentially 3 types of bugs/errors
· compile errors
· program does not compile but compiler tells you why· syntax errors, type mismatch errors, ...
· these are your fault
· runtime errors
· cannot be determined at compile time· sometimes require re-design of code
· these may be your fault
· logical errors
· non-syntax mistakes in your code· Java cannot detect and explain these errors· may be very hard to �nd...· these are definitely your fault
6 / 28
![Page 13: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/13.jpg)
Bugs...
essentially 3 types of bugs/errors
· compile errors
· program does not compile but compiler tells you why· syntax errors, type mismatch errors, ...
· these are your fault
· runtime errors
· cannot be determined at compile time· sometimes require re-design of code
· these may be your fault
· logical errors
· non-syntax mistakes in your code· Java cannot detect and explain these errors· may be very hard to �nd...
· these are definitely your fault
6 / 28
![Page 14: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/14.jpg)
Bugs...
essentially 3 types of bugs/errors
· compile errors
· program does not compile but compiler tells you why· syntax errors, type mismatch errors, ...· these are your fault
· runtime errors
· cannot be determined at compile time· sometimes require re-design of code
· these may be your fault
· logical errors
· non-syntax mistakes in your code· Java cannot detect and explain these errors· may be very hard to �nd...
· these are definitely your fault
6 / 28
![Page 15: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/15.jpg)
Bugs...
essentially 3 types of bugs/errors
· compile errors
· program does not compile but compiler tells you why· syntax errors, type mismatch errors, ...· these are your fault
· runtime errors
· cannot be determined at compile time· sometimes require re-design of code· these may be your fault
· logical errors
· non-syntax mistakes in your code· Java cannot detect and explain these errors· may be very hard to �nd...
· these are definitely your fault
6 / 28
![Page 16: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/16.jpg)
Bugs...
essentially 3 types of bugs/errors
· compile errors
· program does not compile but compiler tells you why· syntax errors, type mismatch errors, ...· these are your fault
· runtime errors
· cannot be determined at compile time· sometimes require re-design of code· these may be your fault
· logical errors
· non-syntax mistakes in your code· Java cannot detect and explain these errors· may be very hard to �nd...· these are definitely your fault
6 / 28
![Page 17: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/17.jpg)
Bugs...
· �rst need to �nd them
· compile errors are found for free?
· test, test, test, ...· println is your friend
· next need to �nd in your code where they occur
· JVM might tell you where code crashed (runtime error)· observable error may have been caused elsewhere though...· play computer! backtrack...· might be easy or hard
· next we �x the bug
· if we know exactly where the bugs originates, often easy to �x· serious bugs may require rethinking your code/objects
7 / 28
![Page 18: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/18.jpg)
Bugs...
· �rst need to �nd them
· compile errors are found for free?
· test, test, test, ...· println is your friend
· next need to �nd in your code where they occur
· JVM might tell you where code crashed (runtime error)· observable error may have been caused elsewhere though...· play computer! backtrack...· might be easy or hard
· next we �x the bug
· if we know exactly where the bugs originates, often easy to �x· serious bugs may require rethinking your code/objects
7 / 28
![Page 19: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/19.jpg)
Bugs...
· �rst need to �nd them· compile errors are found for free?
· test, test, test, ...· println is your friend
· next need to �nd in your code where they occur
· JVM might tell you where code crashed (runtime error)· observable error may have been caused elsewhere though...· play computer! backtrack...· might be easy or hard
· next we �x the bug
· if we know exactly where the bugs originates, often easy to �x· serious bugs may require rethinking your code/objects
7 / 28
![Page 20: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/20.jpg)
Bugs...
· �rst need to �nd them· compile errors are found for free?
· test, test, test, ...
· println is your friend
· next need to �nd in your code where they occur
· JVM might tell you where code crashed (runtime error)· observable error may have been caused elsewhere though...· play computer! backtrack...· might be easy or hard
· next we �x the bug
· if we know exactly where the bugs originates, often easy to �x· serious bugs may require rethinking your code/objects
7 / 28
![Page 21: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/21.jpg)
Bugs...
· �rst need to �nd them· compile errors are found for free?
· test, test, test, ...· println is your friend
· next need to �nd in your code where they occur
· JVM might tell you where code crashed (runtime error)· observable error may have been caused elsewhere though...· play computer! backtrack...· might be easy or hard
· next we �x the bug
· if we know exactly where the bugs originates, often easy to �x· serious bugs may require rethinking your code/objects
7 / 28
![Page 22: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/22.jpg)
Bugs...
· �rst need to �nd them· compile errors are found for free?
· test, test, test, ...· println is your friend
· next need to �nd in your code where they occur
· JVM might tell you where code crashed (runtime error)· observable error may have been caused elsewhere though...· play computer! backtrack...· might be easy or hard
· next we �x the bug
· if we know exactly where the bugs originates, often easy to �x· serious bugs may require rethinking your code/objects
7 / 28
![Page 23: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/23.jpg)
Bugs...
· �rst need to �nd them· compile errors are found for free?
· test, test, test, ...· println is your friend
· next need to �nd in your code where they occur· JVM might tell you where code crashed (runtime error)
· observable error may have been caused elsewhere though...· play computer! backtrack...· might be easy or hard
· next we �x the bug
· if we know exactly where the bugs originates, often easy to �x· serious bugs may require rethinking your code/objects
7 / 28
![Page 24: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/24.jpg)
Bugs...
· �rst need to �nd them· compile errors are found for free?
· test, test, test, ...· println is your friend
· next need to �nd in your code where they occur· JVM might tell you where code crashed (runtime error)· observable error may have been caused elsewhere though...
· play computer! backtrack...· might be easy or hard
· next we �x the bug
· if we know exactly where the bugs originates, often easy to �x· serious bugs may require rethinking your code/objects
7 / 28
![Page 25: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/25.jpg)
Bugs...
· �rst need to �nd them· compile errors are found for free?
· test, test, test, ...· println is your friend
· next need to �nd in your code where they occur· JVM might tell you where code crashed (runtime error)· observable error may have been caused elsewhere though...· play computer! backtrack...
· might be easy or hard
· next we �x the bug
· if we know exactly where the bugs originates, often easy to �x· serious bugs may require rethinking your code/objects
7 / 28
![Page 26: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/26.jpg)
Bugs...
· �rst need to �nd them· compile errors are found for free?
· test, test, test, ...· println is your friend
· next need to �nd in your code where they occur· JVM might tell you where code crashed (runtime error)· observable error may have been caused elsewhere though...· play computer! backtrack...· might be easy or hard
· next we �x the bug
· if we know exactly where the bugs originates, often easy to �x· serious bugs may require rethinking your code/objects
7 / 28
![Page 27: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/27.jpg)
Bugs...
· �rst need to �nd them· compile errors are found for free?
· test, test, test, ...· println is your friend
· next need to �nd in your code where they occur· JVM might tell you where code crashed (runtime error)· observable error may have been caused elsewhere though...· play computer! backtrack...· might be easy or hard
· next we �x the bug
· if we know exactly where the bugs originates, often easy to �x· serious bugs may require rethinking your code/objects
7 / 28
![Page 28: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/28.jpg)
Bugs...
· �rst need to �nd them· compile errors are found for free?
· test, test, test, ...· println is your friend
· next need to �nd in your code where they occur· JVM might tell you where code crashed (runtime error)· observable error may have been caused elsewhere though...· play computer! backtrack...· might be easy or hard
· next we �x the bug· if we know exactly where the bugs originates, often easy to �x
· serious bugs may require rethinking your code/objects
7 / 28
![Page 29: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/29.jpg)
Bugs...
· �rst need to �nd them· compile errors are found for free?
· test, test, test, ...· println is your friend
· next need to �nd in your code where they occur· JVM might tell you where code crashed (runtime error)· observable error may have been caused elsewhere though...· play computer! backtrack...· might be easy or hard
· next we �x the bug· if we know exactly where the bugs originates, often easy to �x· serious bugs may require rethinking your code/objects
7 / 28
![Page 30: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/30.jpg)
Bugs...
part of the problem is that we don't live in a perfect world...
· people do not follow API speci�cations (preconditions)
· people do weird things with your code...
· �les get corrupted
you have no control over how people use your codeyou have no control over the universe your code is running in
· need to write robust code
8 / 28
![Page 31: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/31.jpg)
Bugs...
part of the problem is that we don't live in a perfect world...
· people do not follow API speci�cations (preconditions)
· people do weird things with your code...
· �les get corrupted
you have no control over how people use your codeyou have no control over the universe your code is running in
· need to write robust code
8 / 28
![Page 32: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/32.jpg)
Bugs...
part of the problem is that we don't live in a perfect world...
· people do not follow API speci�cations (preconditions)
· people do weird things with your code...
· �les get corrupted
you have no control over how people use your codeyou have no control over the universe your code is running in
· need to write robust code
8 / 28
![Page 33: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/33.jpg)
Bugs...
part of the problem is that we don't live in a perfect world...
· people do not follow API speci�cations (preconditions)
· people do weird things with your code...
· �les get corrupted
you have no control over how people use your codeyou have no control over the universe your code is running in
· need to write robust code
8 / 28
![Page 34: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/34.jpg)
Bugs...
part of the problem is that we don't live in a perfect world...
· people do not follow API speci�cations (preconditions)
· people do weird things with your code...
· �les get corrupted
you have no control over how people use your codeyou have no control over the universe your code is running in
· need to write robust code
8 / 28
![Page 35: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/35.jpg)
Bugs...
part of the problem is that we don't live in a perfect world...
· people do not follow API speci�cations (preconditions)
· people do weird things with your code...
· �les get corrupted
you have no control over how people use your codeyou have no control over the universe your code is running in
· need to write robust code
8 / 28
![Page 36: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/36.jpg)
Bugs...
we could write code to check for all possibilities in our code
· error-checking is code added to your code to look for bad data
· error-handling is what you do when bad data is found
in Java we use Exceptions...
· an Exception is an error that occurs in your code
· Exception Handling is what you do when an exception is found
goal of using exceptions
· you want your program to die gracefully
· you want to program to recover from bad data
9 / 28
![Page 37: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/37.jpg)
Bugs...
we could write code to check for all possibilities in our code
· error-checking is code added to your code to look for bad data
· error-handling is what you do when bad data is found
in Java we use Exceptions...
· an Exception is an error that occurs in your code
· Exception Handling is what you do when an exception is found
goal of using exceptions
· you want your program to die gracefully
· you want to program to recover from bad data
9 / 28
![Page 38: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/38.jpg)
Bugs...
we could write code to check for all possibilities in our code
· error-checking is code added to your code to look for bad data
· error-handling is what you do when bad data is found
in Java we use Exceptions...
· an Exception is an error that occurs in your code
· Exception Handling is what you do when an exception is found
goal of using exceptions
· you want your program to die gracefully
· you want to program to recover from bad data
9 / 28
![Page 39: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/39.jpg)
Bugs...
we could write code to check for all possibilities in our code
· error-checking is code added to your code to look for bad data
· error-handling is what you do when bad data is found
in Java we use Exceptions...
· an Exception is an error that occurs in your code
· Exception Handling is what you do when an exception is found
goal of using exceptions
· you want your program to die gracefully
· you want to program to recover from bad data
9 / 28
![Page 40: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/40.jpg)
Bugs...
we could write code to check for all possibilities in our code
· error-checking is code added to your code to look for bad data
· error-handling is what you do when bad data is found
in Java we use Exceptions...
· an Exception is an error that occurs in your code
· Exception Handling is what you do when an exception is found
goal of using exceptions
· you want your program to die gracefully
· you want to program to recover from bad data
9 / 28
![Page 41: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/41.jpg)
Bugs...
we could write code to check for all possibilities in our code
· error-checking is code added to your code to look for bad data
· error-handling is what you do when bad data is found
in Java we use Exceptions...
· an Exception is an error that occurs in your code
· Exception Handling is what you do when an exception is found
goal of using exceptions
· you want your program to die gracefully
· you want to program to recover from bad data
9 / 28
![Page 42: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/42.jpg)
Bugs...
we could write code to check for all possibilities in our code
· error-checking is code added to your code to look for bad data
· error-handling is what you do when bad data is found
in Java we use Exceptions...
· an Exception is an error that occurs in your code
· Exception Handling is what you do when an exception is found
goal of using exceptions
· you want your program to die gracefully
· you want to program to recover from bad data
9 / 28
![Page 43: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/43.jpg)
Bugs...
we could write code to check for all possibilities in our code
· error-checking is code added to your code to look for bad data
· error-handling is what you do when bad data is found
in Java we use Exceptions...
· an Exception is an error that occurs in your code
· Exception Handling is what you do when an exception is found
goal of using exceptions
· you want your program to die gracefully
· you want to program to recover from bad data
9 / 28
![Page 44: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/44.jpg)
Bugs...
we could write code to check for all possibilities in our code
· error-checking is code added to your code to look for bad data
· error-handling is what you do when bad data is found
in Java we use Exceptions...
· an Exception is an error that occurs in your code
· Exception Handling is what you do when an exception is found
goal of using exceptions
· you want your program to die gracefully
· you want to program to recover from bad data
9 / 28
![Page 45: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/45.jpg)
Exceptions...
in Java, exceptions are thrown
· the JVM automatically does this
· you explicitly do this in your code
in Java, thrown exceptions are always caught
· explicitly caught by your code
(graceful)
· delegated to someone else's code to be caught
(potentially graceful)
· caught by the JVM if everyone delegates
(ugly)
10 / 28
![Page 46: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/46.jpg)
Exceptions...
in Java, exceptions are thrown
· the JVM automatically does this
· you explicitly do this in your code
in Java, thrown exceptions are always caught
· explicitly caught by your code
(graceful)
· delegated to someone else's code to be caught
(potentially graceful)
· caught by the JVM if everyone delegates
(ugly)
10 / 28
![Page 47: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/47.jpg)
Exceptions...
in Java, exceptions are thrown
· the JVM automatically does this
· you explicitly do this in your code
in Java, thrown exceptions are always caught
· explicitly caught by your code
(graceful)
· delegated to someone else's code to be caught
(potentially graceful)
· caught by the JVM if everyone delegates
(ugly)
10 / 28
![Page 48: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/48.jpg)
Exceptions...
in Java, exceptions are thrown
· the JVM automatically does this
· you explicitly do this in your code
in Java, thrown exceptions are always caught
· explicitly caught by your code
(graceful)
· delegated to someone else's code to be caught
(potentially graceful)
· caught by the JVM if everyone delegates
(ugly)
10 / 28
![Page 49: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/49.jpg)
Exceptions...
in Java, exceptions are thrown
· the JVM automatically does this
· you explicitly do this in your code
in Java, thrown exceptions are always caught
· explicitly caught by your code
(graceful)
· delegated to someone else's code to be caught
(potentially graceful)
· caught by the JVM if everyone delegates
(ugly)
10 / 28
![Page 50: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/50.jpg)
Exceptions...
in Java, exceptions are thrown
· the JVM automatically does this
· you explicitly do this in your code
in Java, thrown exceptions are always caught
· explicitly caught by your code
(graceful)
· delegated to someone else's code to be caught
(potentially graceful)
· caught by the JVM if everyone delegates
(ugly)
10 / 28
![Page 51: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/51.jpg)
Exceptions...
in Java, exceptions are thrown
· the JVM automatically does this
· you explicitly do this in your code
in Java, thrown exceptions are always caught
· explicitly caught by your code
(graceful)
· delegated to someone else's code to be caught
(potentially graceful)
· caught by the JVM if everyone delegates
(ugly)
10 / 28
![Page 52: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/52.jpg)
Exceptions...
in Java, exceptions are thrown
· the JVM automatically does this
· you explicitly do this in your code
in Java, thrown exceptions are always caught
· explicitly caught by your code (graceful)
· delegated to someone else's code to be caught (potentially graceful)
· caught by the JVM if everyone delegates (ugly)
10 / 28
![Page 53: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/53.jpg)
Exceptions...
in Java, exceptions are objects
Error Class
· unrecoverable errors
· java.lang.StackOverflowError
· java.lang.OutOfMemoryError
· you do not generally catch these yourself
(you �x your code so it doesn't happen again!)
11 / 28
![Page 54: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/54.jpg)
Exceptions...
in Java, exceptions are objects
Error Class
· unrecoverable errors
· java.lang.StackOverflowError
· java.lang.OutOfMemoryError
· you do not generally catch these yourself
(you �x your code so it doesn't happen again!)
11 / 28
![Page 55: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/55.jpg)
Exceptions...
in Java, exceptions are objects
Error Class
· unrecoverable errors
· java.lang.StackOverflowError
· java.lang.OutOfMemoryError
· you do not generally catch these yourself
(you �x your code so it doesn't happen again!)
11 / 28
![Page 56: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/56.jpg)
Exceptions...
in Java, exceptions are objects
Error Class
· unrecoverable errors· java.lang.StackOverflowError
· java.lang.OutOfMemoryError
· you do not generally catch these yourself
(you �x your code so it doesn't happen again!)
11 / 28
![Page 57: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/57.jpg)
Exceptions...
in Java, exceptions are objects
Error Class
· unrecoverable errors· java.lang.StackOverflowError
· java.lang.OutOfMemoryError
· you do not generally catch these yourself
(you �x your code so it doesn't happen again!)
11 / 28
![Page 58: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/58.jpg)
Exceptions...
in Java, exceptions are objects
Error Class
· unrecoverable errors· java.lang.StackOverflowError
· java.lang.OutOfMemoryError
· you do not generally catch these yourself(you �x your code so it doesn't happen again!)
11 / 28
![Page 59: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/59.jpg)
Exceptions...
in Java, exceptions are objects
Exception Class
· less severe errors (we might be able to recover from these)
· there are checked and unchecked exceptions
· checked exceptions (Exception Class)
· compiler checks that these are explicitly caught(if there is a throw there must be a catch)
· IllegalAccessException (try to violate access modi�er)FileNotFoundException (�le is not found)
· unchecked exceptions (RuntimeException class)
· compiler does not check for a catch(typically left for JVM to crash program)
· you should rethink your code to avoid these...· ArtithmeticException (divide by zero for example)NullpointerException
IndexOutOfBoundsException
12 / 28
![Page 60: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/60.jpg)
Exceptions...
in Java, exceptions are objects
Exception Class
· less severe errors (we might be able to recover from these)
· there are checked and unchecked exceptions
· checked exceptions (Exception Class)
· compiler checks that these are explicitly caught(if there is a throw there must be a catch)
· IllegalAccessException (try to violate access modi�er)FileNotFoundException (�le is not found)
· unchecked exceptions (RuntimeException class)
· compiler does not check for a catch(typically left for JVM to crash program)
· you should rethink your code to avoid these...· ArtithmeticException (divide by zero for example)NullpointerException
IndexOutOfBoundsException
12 / 28
![Page 61: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/61.jpg)
Exceptions...
in Java, exceptions are objects
Exception Class
· less severe errors (we might be able to recover from these)
· there are checked and unchecked exceptions
· checked exceptions (Exception Class)
· compiler checks that these are explicitly caught(if there is a throw there must be a catch)
· IllegalAccessException (try to violate access modi�er)FileNotFoundException (�le is not found)
· unchecked exceptions (RuntimeException class)
· compiler does not check for a catch(typically left for JVM to crash program)
· you should rethink your code to avoid these...· ArtithmeticException (divide by zero for example)NullpointerException
IndexOutOfBoundsException
12 / 28
![Page 62: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/62.jpg)
Exceptions...
in Java, exceptions are objects
Exception Class
· less severe errors (we might be able to recover from these)
· there are checked and unchecked exceptions
· checked exceptions (Exception Class)
· compiler checks that these are explicitly caught(if there is a throw there must be a catch)
· IllegalAccessException (try to violate access modi�er)FileNotFoundException (�le is not found)
· unchecked exceptions (RuntimeException class)
· compiler does not check for a catch(typically left for JVM to crash program)
· you should rethink your code to avoid these...· ArtithmeticException (divide by zero for example)NullpointerException
IndexOutOfBoundsException
12 / 28
![Page 63: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/63.jpg)
Exceptions...
in Java, exceptions are objects
Exception Class
· less severe errors (we might be able to recover from these)
· there are checked and unchecked exceptions
· checked exceptions (Exception Class)· compiler checks that these are explicitly caught(if there is a throw there must be a catch)
· IllegalAccessException (try to violate access modi�er)FileNotFoundException (�le is not found)
· unchecked exceptions (RuntimeException class)
· compiler does not check for a catch(typically left for JVM to crash program)
· you should rethink your code to avoid these...· ArtithmeticException (divide by zero for example)NullpointerException
IndexOutOfBoundsException
12 / 28
![Page 64: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/64.jpg)
Exceptions...
in Java, exceptions are objects
Exception Class
· less severe errors (we might be able to recover from these)
· there are checked and unchecked exceptions
· checked exceptions (Exception Class)· compiler checks that these are explicitly caught(if there is a throw there must be a catch)
· IllegalAccessException (try to violate access modi�er)FileNotFoundException (�le is not found)
· unchecked exceptions (RuntimeException class)
· compiler does not check for a catch(typically left for JVM to crash program)
· you should rethink your code to avoid these...· ArtithmeticException (divide by zero for example)NullpointerException
IndexOutOfBoundsException
12 / 28
![Page 65: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/65.jpg)
Exceptions...
in Java, exceptions are objects
Exception Class
· less severe errors (we might be able to recover from these)
· there are checked and unchecked exceptions
· checked exceptions (Exception Class)· compiler checks that these are explicitly caught(if there is a throw there must be a catch)
· IllegalAccessException (try to violate access modi�er)FileNotFoundException (�le is not found)
· unchecked exceptions (RuntimeException class)
· compiler does not check for a catch(typically left for JVM to crash program)
· you should rethink your code to avoid these...· ArtithmeticException (divide by zero for example)NullpointerException
IndexOutOfBoundsException
12 / 28
![Page 66: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/66.jpg)
Exceptions...
in Java, exceptions are objects
Exception Class
· less severe errors (we might be able to recover from these)
· there are checked and unchecked exceptions
· checked exceptions (Exception Class)· compiler checks that these are explicitly caught(if there is a throw there must be a catch)
· IllegalAccessException (try to violate access modi�er)FileNotFoundException (�le is not found)
· unchecked exceptions (RuntimeException class)· compiler does not check for a catch(typically left for JVM to crash program)
· you should rethink your code to avoid these...· ArtithmeticException (divide by zero for example)NullpointerException
IndexOutOfBoundsException
12 / 28
![Page 67: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/67.jpg)
Exceptions...
in Java, exceptions are objects
Exception Class
· less severe errors (we might be able to recover from these)
· there are checked and unchecked exceptions
· checked exceptions (Exception Class)· compiler checks that these are explicitly caught(if there is a throw there must be a catch)
· IllegalAccessException (try to violate access modi�er)FileNotFoundException (�le is not found)
· unchecked exceptions (RuntimeException class)· compiler does not check for a catch(typically left for JVM to crash program)
· you should rethink your code to avoid these...
· ArtithmeticException (divide by zero for example)NullpointerException
IndexOutOfBoundsException
12 / 28
![Page 68: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/68.jpg)
Exceptions...
in Java, exceptions are objects
Exception Class
· less severe errors (we might be able to recover from these)
· there are checked and unchecked exceptions
· checked exceptions (Exception Class)· compiler checks that these are explicitly caught(if there is a throw there must be a catch)
· IllegalAccessException (try to violate access modi�er)FileNotFoundException (�le is not found)
· unchecked exceptions (RuntimeException class)· compiler does not check for a catch(typically left for JVM to crash program)
· you should rethink your code to avoid these...· ArtithmeticException (divide by zero for example)NullpointerException
IndexOutOfBoundsException
12 / 28
![Page 69: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/69.jpg)
Exceptions...
13 / 28
![Page 70: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/70.jpg)
let's take a break...for 5 minutes
14 / 28
![Page 71: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/71.jpg)
Exceptions...
new Java keywords
· throws
· used in method declaration· says that this method is delegating this exception
· try/catch/finally
· used to execute code and handle exceptions thrown· "try" to execute this code..."catch" any thrown exceptions and handle them"�nally" execute some code after everything is done
· throw
· explicitly throw an exception
15 / 28
![Page 72: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/72.jpg)
Exceptions...
new Java keywords
· throws
· used in method declaration· says that this method is delegating this exception
· try/catch/finally
· used to execute code and handle exceptions thrown· "try" to execute this code..."catch" any thrown exceptions and handle them"�nally" execute some code after everything is done
· throw
· explicitly throw an exception
15 / 28
![Page 73: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/73.jpg)
Exceptions...
new Java keywords
· throws
· used in method declaration· says that this method is delegating this exception
· try/catch/finally
· used to execute code and handle exceptions thrown· "try" to execute this code..."catch" any thrown exceptions and handle them"�nally" execute some code after everything is done
· throw
· explicitly throw an exception
15 / 28
![Page 74: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/74.jpg)
Exceptions...
new Java keywords
· throws
· used in method declaration· says that this method is delegating this exception
· try/catch/finally
· used to execute code and handle exceptions thrown· "try" to execute this code..."catch" any thrown exceptions and handle them"�nally" execute some code after everything is done
· throw
· explicitly throw an exception
15 / 28
![Page 75: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/75.jpg)
Exceptions...
new Java keywords
· throws
· used in method declaration· says that this method is delegating this exception
· try/catch/finally· used to execute code and handle exceptions thrown
· "try" to execute this code..."catch" any thrown exceptions and handle them"�nally" execute some code after everything is done
· throw
· explicitly throw an exception
15 / 28
![Page 76: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/76.jpg)
Exceptions...
new Java keywords
· throws
· used in method declaration· says that this method is delegating this exception
· try/catch/finally· used to execute code and handle exceptions thrown· "try" to execute this code..."catch" any thrown exceptions and handle them"�nally" execute some code after everything is done
· throw
· explicitly throw an exception
15 / 28
![Page 77: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/77.jpg)
Exceptions...
new Java keywords
· throws
· used in method declaration· says that this method is delegating this exception
· try/catch/finally· used to execute code and handle exceptions thrown· "try" to execute this code..."catch" any thrown exceptions and handle them"�nally" execute some code after everything is done
· throw
· explicitly throw an exception
15 / 28
![Page 78: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/78.jpg)
Exceptions...
new Java keywords
· throws
· used in method declaration· says that this method is delegating this exception
· try/catch/finally· used to execute code and handle exceptions thrown· "try" to execute this code..."catch" any thrown exceptions and handle them"�nally" execute some code after everything is done
· throw
· explicitly throw an exception
15 / 28
![Page 79: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/79.jpg)
Throws
void openFile(String fname) throws java.io.FileNotFoundException{
...
}
tells the compiler that this method might
· explicitly throw a java.io.FileNotFoundException objector
calls a method that might
· explicitly throw a java.io.FileNotFoundException objectorcalls a method that might
· explicitly throw a java.io.FileNotFoundException object
or
calls a method that might
...
...
...
explicitly throw a java.io.FileNotFoundException object
16 / 28
![Page 80: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/80.jpg)
Throws
void openFile(String fname) throws java.io.FileNotFoundException{
...
}
tells the compiler that this method might
· explicitly throw a java.io.FileNotFoundException objector
calls a method that might
· explicitly throw a java.io.FileNotFoundException objectorcalls a method that might
· explicitly throw a java.io.FileNotFoundException object
or
calls a method that might
...
...
...
explicitly throw a java.io.FileNotFoundException object
16 / 28
![Page 81: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/81.jpg)
Throws
void openFile(String fname) throws java.io.FileNotFoundException{
...
}
tells the compiler that this method might
· explicitly throw a java.io.FileNotFoundException objectorcalls a method that might
· explicitly throw a java.io.FileNotFoundException objector
calls a method that might
· explicitly throw a java.io.FileNotFoundException object
or
calls a method that might
...
...
...
explicitly throw a java.io.FileNotFoundException object
16 / 28
![Page 82: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/82.jpg)
Throws
void openFile(String fname) throws java.io.FileNotFoundException{
...
}
tells the compiler that this method might
· explicitly throw a java.io.FileNotFoundException objectorcalls a method that might
· explicitly throw a java.io.FileNotFoundException objector
calls a method that might
· explicitly throw a java.io.FileNotFoundException object
or
calls a method that might
...
...
...
explicitly throw a java.io.FileNotFoundException object
16 / 28
![Page 83: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/83.jpg)
Throws
void openFile(String fname) throws java.io.FileNotFoundException{
...
}
tells the compiler that this method might
· explicitly throw a java.io.FileNotFoundException objectorcalls a method that might
· explicitly throw a java.io.FileNotFoundException objectorcalls a method that might
· explicitly throw a java.io.FileNotFoundException object
or
calls a method that might
...
...
...
explicitly throw a java.io.FileNotFoundException object
16 / 28
![Page 84: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/84.jpg)
Throws
void openFile(String fname) throws java.io.FileNotFoundException{
...
}
tells the compiler that this method might
· explicitly throw a java.io.FileNotFoundException objectorcalls a method that might
· explicitly throw a java.io.FileNotFoundException objectorcalls a method that might
· explicitly throw a java.io.FileNotFoundException object
or
calls a method that might
...
...
...
explicitly throw a java.io.FileNotFoundException object
16 / 28
![Page 85: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/85.jpg)
Throws
void openFile(String fname) throws java.io.FileNotFoundException{
...
}
tells the compiler that this method might
· explicitly throw a java.io.FileNotFoundException objectorcalls a method that might
· explicitly throw a java.io.FileNotFoundException objectorcalls a method that might
· explicitly throw a java.io.FileNotFoundException object
or
calls a method that might
...
...
...
explicitly throw a java.io.FileNotFoundException object
16 / 28
![Page 86: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/86.jpg)
Throws
void openFile(String fname) throws java.io.FileNotFoundException{
...
}
tells the compiler that this method might
· explicitly throw a java.io.FileNotFoundException objectorcalls a method that might
· explicitly throw a java.io.FileNotFoundException objectorcalls a method that might
· explicitly throw a java.io.FileNotFoundException object
or
calls a method that might
...
...
...
explicitly throw a java.io.FileNotFoundException object
16 / 28
![Page 87: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/87.jpg)
Throws
void openFile(String fname) throws java.io.FileNotFoundException{
...
}
let's look at an example
17 / 28
![Page 88: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/88.jpg)
Try/Catch
· use throws to delegate exception handling
· use try and catch to handle the exception yourself
try{
block of code to try}
catch(Exception e){
block of codeto execute if exception is caught
}
catch(RuntimeException re){
block of codeto execute if exception is caught
}
18 / 28
![Page 89: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/89.jpg)
Try/Catch
· use throws to delegate exception handling
· use try and catch to handle the exception yourself
try{
block of code to try}
catch(Exception e){
block of codeto execute if exception is caught
}
catch(RuntimeException re){
block of codeto execute if exception is caught
}
18 / 28
![Page 90: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/90.jpg)
Try/Catch
· use throws to delegate exception handling
· use try and catch to handle the exception yourself
try{
block of code to try}
catch(Exception e){
block of codeto execute if exception is caught
}
catch(RuntimeException re){
block of codeto execute if exception is caught
}
18 / 28
![Page 91: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/91.jpg)
Try/Catch
· use throws to delegate exception handling
· use try and catch to handle the exception yourself
let's look at the same example...
19 / 28
![Page 92: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/92.jpg)
Try/Catch
order matters! class hierarchy matters!
java.lang.Object
↑java.lang.Throwable
↑java.lang.Exception
↑java.io.IOException
↑java.io.FileNotFoundException
20 / 28
![Page 93: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/93.jpg)
Try/Catch
order matters! class hierarchy matters!
Object
↑Throwable
↑Exception
↑java.io.IOException
↑java.io.FileNotFoundException
20 / 28
![Page 94: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/94.jpg)
Try/Catch
try{
block of code to try}
catch(Exception e){
block of code toexecute if exceptionthrown
}
catch(RuntimeException re){
block of code toexecute if exceptionthrown
}
catch(IOException ioe){
block of code toexecute if exceptionthrown
}
{
block of code to try}
if (Exception is thrown){
block of code toexecute if exceptionthrown
}
else if (RuntimeException){
block of code toexecute if exceptionthrown
}
else if (IOException){
block of code toexecute if exceptionthrown
}
21 / 28
![Page 95: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/95.jpg)
Try/Catch
order matters! class hierarchy matters!
Object
↑Throwable
↑Exception
↑java.io.IOException
↑java.io.FileNotFoundException
22 / 28
![Page 96: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/96.jpg)
Try/Catch/Finaly
· try executes a block of code
· if exception thrown, catch it and handle it
· after try and possibly catch code executes, we finally executesome �nishing code
try{
block of code to try}
catch(Throwable e){
block of codeto execute if exception is caught
}
finally{ // like a funny else
block of code to executeREGARDLESS of what happens above
}
23 / 28
![Page 97: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/97.jpg)
Try/Catch/Finaly
· try executes a block of code
· if exception thrown, catch it and handle it
· after try and possibly catch code executes, we finally executesome �nishing code
try{
block of code to try}
catch(Throwable e){
block of codeto execute if exception is caught
}
finally{ // like a funny else
block of code to executeREGARDLESS of what happens above
}
23 / 28
![Page 98: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/98.jpg)
Try/Catch/Finaly
· try executes a block of code
· if exception thrown, catch it and handle it
· after try and possibly catch code executes, we finally executesome �nishing code
try{
block of code to try}
catch(Throwable e){
block of codeto execute if exception is caught
}
finally{ // like a funny else
block of code to executeREGARDLESS of what happens above
}
23 / 28
![Page 99: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/99.jpg)
Throw
throw is the mechanism to explicitly throw an exception.
· throw new Exception("something bad here...");
creates a new Exception object and throws it
· throw e;
throws an existing exception(e must be a Throwable object )
24 / 28
![Page 100: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/100.jpg)
Throw
throw is the mechanism to explicitly throw an exception.
· throw new Exception("something bad here...");
creates a new Exception object and throws it
· throw e;
throws an existing exception(e must be a Throwable object )
24 / 28
![Page 101: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/101.jpg)
Throw
throw is the mechanism to explicitly throw an exception.
· throw new Exception("something bad here...");
creates a new Exception object and throws it
· throw e;
throws an existing exception(e must be a Throwable object )
24 / 28
![Page 102: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/102.jpg)
Making Your Own Exceptions
you create your own custom exceptions by extending an appropriateThowable class
25 / 28
![Page 103: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/103.jpg)
Making Your Own Exceptions
you create your own custom exceptions by extending an appropriateThowable class
25 / 28
![Page 104: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/104.jpg)
Making Your Own Exceptions
you create your own custom exceptions by extending an appropriateThowable class
public class BadCardRank extends Exception {
public BadCardRank(){
super("Rank of card is invalid");
}
}
26 / 28
![Page 105: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/105.jpg)
Throwable
the Throwable class is the root of all exceptions in Java
· toString()
· returns short description of this object
· getMessage()
· returns the message as input with the constructor
· printStackTrace()
· prints the stack trace to standard error
27 / 28
![Page 106: 200 errors found: Error: /U/TestGQ.java:314: compareTo ...• next need to nd in your code where they occur • JVM might tell you where code crashed (runtime error) ... • println](https://reader033.fdocuments.in/reader033/viewer/2022050116/5f4d46fa334cb42393033863/html5/thumbnails/106.jpg)
let's take a break...for 9900 minutes
28 / 28