Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Logging an Exception in Java 
 

This section introduces you the concept of logging exception handling.

 

Logging an Exception in Java

                         

This section introduces you the concept of logging exception handling. When certain conditions are not followed or wrong then compiler shows a message which is mentioned under the specific exception. Exception is an event that occurred when the program is execute or in running time. This is used for the error handling. There are several errors are caught by different specific exceptions like the "divided by zero" error is under the ArithmeticException, blank array is under the NullPointerException, blank stack is a EmptyStackException and many others errors are handled by many exceptions like that.

Description of program:
This program represents two exceptions like: ArithmeticException and NullPointerException by Logger object. Program contains two method DivByZero() method and ArrayBound() method which provides an exception at the running time of program. The DivByZero method throws ArithmethicException because '1' is not divisible by '0' and another method gives the working illustration of NullPointerException that catch the error when the array is blank. 

Description of code:

log(Level level, String message, Throwable thrown):
Above method shows a log message generated by Throwable information to the system. It takes level provided by logger and also a string type value with given message and throwable information at the time of running.

Here is the code of program:

import java.io.*;
import java.util.logging.*;

public class LogException{
  public static void main(String[] args) {
    LogException l = new LogException();
  }
  public void DivByZero() {
    System.out.println(1/0);
  }
  int arr[];
  public void ArrayBound() {
    System.out.println(arr[0]);
  }
  public LogException(){
    Logger log = Logger.getLogger("");
    try{
      DivByZero();
    }
    catch (Exception e){
      log.log(Level.WARNING, "Can not divede by zero", e.getMessage());
    }
    try{
      ArrayBound();
    }
    catch(Exception ex){
      log.log(Level.INFO, "Array is blank", ex.getMessage());
    }
  }
}

Download this example.

                         

» View all related tutorials
Related Tags: c string ide class reference io references size sed get vi key value field fields this id length max preferences

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.