130 likes | 157 Vues
Learn the importance of proper exception handling in Java, with examples of Checked vs. Unchecked Exceptions and how to deal with various error scenarios. Discover essential tips for effective programming.
E N D
Source Code Online • Please avail yourselves of the many excellent sources for source code, both full applications and snippets. • http://stackoverflow.com/ (best for snippets) • http://www.planet-source-code.com/ (best for full apps) • http://www.freewarejava.com/ • http://www.javagalaxy.com/ • http://www.java2s.com • http://www.javadb.com/
Guidelines for using found source code • If you know the URL where you got it, cite like so: • //http://stackoverflow.com/questions/26305/how-can-i-play-sound-in-java • At minimum, cite the domain: • //method found on stackoverflow.com • Don't copy an entire application; that is plagiarism. • Use found source code within reason.
Cross-Cutting Concerns • Exceptions • Assertions • Logging BlackJack Shoe Dealer
Situations which cause Exceptions (or Errors) to be thrown • An internal Error occurs in the VM (OutOfMemoryError) • An unchecked Exception is generated and thrown (ArrayIndexOutOfBounds) • A checked Exception is thrown (EOFException) • You purposefully throw an Exception.
Exception sequence • Once an exception is generated, the execution sequence immediately terminates until the exception is cuaght (or propogates up the the VM). In practice that means that any code following your statement which threatens to throw an excpetion will NOT be executed if an exception occurs. No return value! • An exception is thrown up the call stack
Some Java naming wierdness in the Exception Handling API • Despite having the 'able' suffix, Throwable is a class, not an interface. • Errors are considered part of the "Exception Handling" API • All Exceptions and Errors occur at Runtime, so RuntimeException is a useless name.
Some things to remember about Exceptions • Anything that inherets from RuntimeException is unchecked.
Intro to Data Structures in Java • Single Lined List • Stack • Binary Tree • others...