Advertisement
Guest User

Untitled

a guest
Mar 4th, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. public static void main(String[] args) throws FileNotFoundException
  2.  
  3. public class ExceptionThrownTest {
  4.  
  5. @Test
  6. public void testingExceptions() {
  7.  
  8. try {
  9. ExceptionThrownTest.main(new String[] {});
  10. } catch (Throwable e) {
  11. assertTrue(e instanceof RuntimeException);
  12. }
  13.  
  14. }
  15.  
  16. public static void main(String[] args) throws FileNotFoundException {
  17.  
  18. dangerousMethod();
  19.  
  20. // Won't be executed because RuntimeException thrown
  21. unreachableMethod();
  22.  
  23. }
  24.  
  25. private static void dangerousMethod() {
  26. throw new RuntimeException();
  27. }
  28.  
  29. private static void unreachableMethod() {
  30. System.out.println("Won't execute");
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement