Embed presentation


















![Keywords
• catch
/* Several catch blocks of differing types can be concatenated.
*/
try {
URL myURL = new URL("http://www.mainejug.org");
InputStream oStream = myURL.openStream();
byte[] myBuffer = new byte[512];
int nCount = 0;
while ((nCount = oStream.read(myBuffer)) != -1) {
System.out.println(new String(myBuffer, 0, nCount));
}
oStream.close();
} catch (MalformedURLException mue) {
System.err.println("MUE: " + mue.toString());
} catch (IOException ioe) {
System.err.println("IOE: " + ioe.toString());
}](https://image.slidesharecdn.com/exceptionslohika-120709091145-phpapp01/75/Exceptions-in-Java-19-2048.jpg)







![New in Java 7
public class OldTry {
public static void main(String[] args) {
OldResource res = null;
try {
res = new OldResource();
res.doSomeWork("Writing an article");
} catch (Exception e) {
System.out.println("Exception Message: " +
e.getMessage() + " Exception Type: " + e.getClass().getName());
} finally {
try {
res.close();
} catch (Exception e) {
System.out.println("Exception Message: " +
e.getMessage() + " Exception Type: " + e.getClass().getName());
}
}
}
}
public class TryWithRes {
public static void main(String[] args) {
try(NewResource res = new NewResource("Res1 closing")){
res.doSomeWork("Listening to podcast");
} catch(Exception e){
System.out.println("Exception: "+
e.getMessage()+" Thrown by: "+e.getClass().getSimpleName());
}
}
}](https://image.slidesharecdn.com/exceptionslohika-120709091145-phpapp01/75/Exceptions-in-Java-27-2048.jpg)




The document provides an overview of exceptions in Java. It defines errors and exceptions, describes different types of exceptions including checked and unchecked exceptions, and explains key exception handling keywords like try, catch, throw, throws, and finally. The document aims to help programmers better understand exceptions and how to properly handle errors in their Java code.


















![Keywords
• catch
/* Several catch blocks of differing types can be concatenated.
*/
try {
URL myURL = new URL("http://www.mainejug.org");
InputStream oStream = myURL.openStream();
byte[] myBuffer = new byte[512];
int nCount = 0;
while ((nCount = oStream.read(myBuffer)) != -1) {
System.out.println(new String(myBuffer, 0, nCount));
}
oStream.close();
} catch (MalformedURLException mue) {
System.err.println("MUE: " + mue.toString());
} catch (IOException ioe) {
System.err.println("IOE: " + ioe.toString());
}](https://image.slidesharecdn.com/exceptionslohika-120709091145-phpapp01/75/Exceptions-in-Java-19-2048.jpg)







![New in Java 7
public class OldTry {
public static void main(String[] args) {
OldResource res = null;
try {
res = new OldResource();
res.doSomeWork("Writing an article");
} catch (Exception e) {
System.out.println("Exception Message: " +
e.getMessage() + " Exception Type: " + e.getClass().getName());
} finally {
try {
res.close();
} catch (Exception e) {
System.out.println("Exception Message: " +
e.getMessage() + " Exception Type: " + e.getClass().getName());
}
}
}
}
public class TryWithRes {
public static void main(String[] args) {
try(NewResource res = new NewResource("Res1 closing")){
res.doSomeWork("Listening to podcast");
} catch(Exception e){
System.out.println("Exception: "+
e.getMessage()+" Thrown by: "+e.getClass().getSimpleName());
}
}
}](https://image.slidesharecdn.com/exceptionslohika-120709091145-phpapp01/75/Exceptions-in-Java-27-2048.jpg)


