Share

Search Java Code Snippets


  Help us in improving the repository. Add new snippets through 'Submit Code Snippet ' link.





#Java - Code Snippets for '#Exception handling' - 2 code snippet(s) found

 Sample 1. Exception handling and logging using Log4j

private static final Logger LOGGER = Logger.getLogger(BuggyBread.class);

public static void main(String[] args) {
   try {
      // Do Something   
   } catch (Throwable t) {
      LOGGER.error("Shit Happens");
   } finally {
      // release the connections
   }
}



   Like      Feedback     exception handling  exceptions  log4j  logging  logger  finally


 Sample 2. Retry in case of exception

public static final int NUMBER_OF_RETRIES = 5;

try {
   // do something
} catch (Exception e) {
   int count;
   for (count = 1; count <= NUMBER_OF_RETRIES; count++) {
      Thread.sleep(5000);
   } catch (InterruptedException e1) {
      try {
         // do something again
         break;
      } catch (Exception ex) {
   }
}

   Like      Feedback     exception handling   exception   Retry in case of exception   for loop   for   Thread.sleep   InterruptedException



Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner



comments powered by Disqus