Guest User

Untitled

a guest
Mar 20th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. catch(Exception exc) { /* won't catch RuntimeException */
  2.  
  3. catch(Throwable exc) { /* will catch RuntimeException */
  4.  
  5. for(Callback cb : callbacks) {
  6. try {
  7. cb.call(item);
  8. }
  9. catch(Exception exc) {
  10. logger.error("Error in callback: ", exc);
  11. }
  12. }
  13.  
  14. public class Test {
  15. public static void main(String[] args) {
  16. try {
  17. throw new RuntimeException("Bang");
  18. } catch (Exception e) {
  19. System.out.println("I caught: " + e);
  20. }
  21. }
  22. }
  23.  
  24. I caught: java.lang.RuntimeException: Bang
  25.  
  26. catch (Exception ex) { ... }
  27.  
  28. class A{//this class will never be initialized because class B won't intialize
  29. static{
  30. try{
  31. classB.someStaticMethod();
  32. }catch(Exception e){
  33. sysout("This comment will never be printed");
  34. }
  35. }
  36. }
  37.  
  38. class B{//this class will never be initialized
  39. static{
  40. int i = 1/0;//throw run time exception
  41. }
  42.  
  43. public static void someStaticMethod(){}
  44. }
Add Comment
Please, Sign In to add comment