/*
* 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 ...
-
In construction. Spring test annotations: @SpringBooTest @DataJpaTest @TestPropertySource @ActiveProfiles @Sql @SpringBootTest It is used f...
-
As the name implies, an anonymous inner class isn’t defined using an explicit name. An anonymous inner class is created when you combine ins...
No comments:
Post a Comment