Results 1 to 5 of 5

Thread: How to catch an Exception in Java?

  1. #1
    Join Date
    Jul 2006
    Posts
    182

    How to catch an Exception in Java?

    Hello friends,
    I have recently started with the Java. Before that I have done C++ and HTML programming language. I have done very less coding of the basic Java. Since, I am new to Java I am not having enough knowledge about it. I am confused with an exceptions. So please tell me what are the exceptions.?? And also explain me how to catch an Exception in Java.?? Help me as soon as possible.!!
    "Yea though I walk through the valley of the shadow of death... I will fear no evil." -Psalms 23

    K8N Diamond Plus (BIOS v1.2)
    AMD Athlon 64 X2 4400+
    Antec TruControl 550W
    NVidia GeForce 7900GT (NGO v1.8466 BETA)
    OCZ Platinum 2x1GB (2-3-2-5)
    SATA: WD740
    PATA: 2xWD2500, WD1200, NEC DVD/RW

  2. #2
    Join Date
    Jul 2006
    Posts
    289

    Re: How to catch an Exception in Java?

    The term exception is used for the phrase "exceptional event". You can define exception as an event, which occurs during the execution of a program, that disrupts the normal flow of the program's instructions. Exceptions let you handle unusual error conditions without cluttering your code with nested ifs after every method call. When an error occurs within a method, the method creates an object and hands it off to the runtime system.
    Signatures reduce available bandwidth

  3. #3
    Join Date
    Jul 2006
    Posts
    286

    Re: How to catch an Exception in Java?

    You should also know about an object that are used by the Exceptions. The object which is known as an exception object contains information about the error. The information also contains the types and the state of the program when the error occurred. There are two kinds of Exceptions, checked and unchecked. Its main to understand the connection which is like a tree : RuntimeException, Error and Exception are derived from Throwable. RuntimeException is derived from Exception, which is derived from Throwable. Error is derived directly from Throwable.
    IF you hate me, please don't mention it. I know who hates me and who doesn't. You really do not have to make fun of people....

  4. #4
    Join Date
    Jul 2006
    Posts
    442

    Re: How to catch an Exception in Java?

    You must write a program in Java that must include the Catch Requirement. In simple words, the code should be able to throw certain exceptions must be enclosed by either of the following :
    • The exception must have a start statement. A try statement that catches the exception. As described in Catching and Handling Exceptions, the try must provide a handler for the exception.
    • A method that specifies that it can throw the exception. Also that method must provide a throws clause that lists the exception.
    Code that fails to satisfy the criteria of the Catch Requirement will not compile.
    "When they give you ruled paper, write the other way..." J.R.J.

  5. #5
    Join Date
    Feb 2008
    Posts
    1,852

    Re: How to catch an Exception in Java?

    I think that once you look at the syntax, the things will become easy for you. The following is the syntax to handle an Exception :
    Code:
    String Trial()
       {
       try
          {
          return ExcepTrial();
          }
       catch ( IOException e )
          {
          return null;
          }
       }
    Then
    Code:
    String ExcepTrial() throws IOException
    {
       int result = readAnotherChar();
       if ( result < 0 ) throw new IOException( "invalid data" );
       return result;
    }

Similar Threads

  1. Exception in Java Web Start
    By Jaganmohini in forum Software Development
    Replies: 6
    Last Post: 27-07-2010, 01:15 PM
  2. Malformed exception in java
    By Amy Adams in forum Software Development
    Replies: 5
    Last Post: 24-03-2010, 08:25 AM
  3. How to prevent from duplicating catch blocks in java?
    By Kasper in forum Software Development
    Replies: 5
    Last Post: 16-02-2010, 08:09 PM
  4. Replies: 5
    Last Post: 18-01-2010, 05:41 PM
  5. Explain Try Catch Block in java
    By cyber-noob in forum Software Development
    Replies: 3
    Last Post: 16-11-2009, 02:13 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,243,998.30016 seconds with 17 queries