/*
* exception happends in catch block won't be caught.
* using nested try block to catch it.
* or throws to caller.
*/
package Ex;
import java.io.IOException;
/**
*
* @author YNZ
*/
class PortConnector {
public PortConnector(int port) throws Exception {
if (Math.random() > 0.5) {
throw new IOException();
}
throw new MyException();
}
}
class ThrowExcep {
@SuppressWarnings("CallToPrintStackTrace")
public static void main(String[] args) throws Exception {
try {
try {
PortConnector pc = new PortConnector(10);
} catch (Exception re) {
re.printStackTrace();
throw new ArithmeticException();
} finally {
System.out.println("finally");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
class MyException extends Exception{
public MyException() {
super("my exception");
}
}
Friday, 20 May 2016
exception happens in the catch block
it cannot be caught, but need adding a nested try block, or throws it to the caller.
Subscribe to:
Post Comments (Atom)
Can Jackson Deserialize Java Time ZonedDateTime
Yes, but must include JSR310. Thus ZonedDateTime can be deserialized directly from JSON response to POJO field. <dependency> <g...
-
Could not extract response: no suitable HttpMessageConverter found for response type [class dk.enettet.evu.core.model.Address] and content ...
-
First time met this hibernate exception. I think this issue should due to one to one relationship. One driver has one car; one car has on...
-
A large object refers to the entity property that is modified by @Lob. It may be persisted in several records. However, in database manage...
No comments:
Post a Comment