Method throwing an exception in Java
//only the method with the keyword "throws"
//can throw an Exception
void methodWithException() throws Exception {
throw new Exception("test exception");
}
//any method can throw an RuntimeException
void methodWithRuntimeException() {
throw new RuntimeException("test exception");
}
- Log in to post comments