Exception in Java
What is Exception and Exception Handling?
normal flow:
exception handling:
exception
Exception Class Hierarchy
Exception Handling
Exception in Java
a try block
a catch block
Exception Handling
Many catch blocks
Exception Handling
Exception Handling
This code does not compile
try {
... }
catch (Exception e) {
return -1;
}
catch (ArithmeticException e) {
return -2;
}
Finally
try {
// Protect one or more statements here
}
catch(Exception e) {
// Report from the exception here
}
finally {
// Perform actions here whether
// or not an exception is thrown
}
Java 7 has introduced a new interface java.lang.AutoCloseable which is extended by java.io.Closeable interface. To use any resource in try-with-resources, it must implement AutoCloseable interface else java compiler will throw compilation error.
try (MyResource sr =
new MyResource()) {
//doSomething with sr
}
MyResource sr =
new MyResource();
try {
//doSomething with sr
} finally {
if (sr == null) {
sr.close();
} }
Statement throws
Statement throws
Statement throws
Statement throw
Creating own checked exception
Creating own checked exception
Creating own unchecked exception
public class Base {
public void doSomething() throws IllegalAccessException{}
}
public class Child extends Base {
@Override
public void doSomething() throws NoSuchMethodException {}
}
Stack Trace
Stack Trace
Stack Trace
Using a Stack Trace
http://www.journaldev.com/1696/exception-handling-in-java#java-7-arm
Если не удалось найти и скачать презентацию, Вы можете заказать его на нашем сайте. Мы постараемся найти нужный Вам материал и отправим по электронной почте. Не стесняйтесь обращаться к нам, если у вас возникли вопросы или пожелания:
Email: Нажмите что бы посмотреть