Hey there! Sign in to join this conversationNew here? Join for free
    • Thread Starter
    Offline

    0
    ReputationRep:
    Can someone please tell me what this section of the code does?
    ________________________________ ________________________________ __

    }
    catch(NumberFormatException ne)
    {
    System.out.println("Invalid value" + ne);
    System.exit(0);
    }
    catch(IOException ioe)
    {
    System.out.println("IO Error :" + ioe);
    System.exit(0);
    }
    Offline

    2
    ReputationRep:
    (Original post by Oppaisenpai)
    Can someone please tell me what this section of the code does?
    ________________________________ ________________________________ __

    }
    catch(NumberFormatException ne)
    {
    System.out.println("Invalid value" + ne);
    System.exit(0);
    }
    catch(IOException ioe)
    {
    System.out.println("IO Error :" + ioe);
    System.exit(0);
    }
    This is part of try/catch statement, its purpose is to run the code in the "try" section; if an error occurs in the code, its looks at the "catch" sections. Here you have got two possible errors that it can catch:

    1) NumberFormatException --> This is an error that is thrown when you try to convert a string to an integer for example.

    2) IOException --> An error that is thrown when something goes with reading/writing to/from files, file permissions, disk space errors.

    If either of these errors occurs in the "try" of the try/catch statement, the code inside the "catch" section will run. In this case, an output will be displayed and the program will halt.

    Hopefully this helped.

    P.S: More information about Exception Handling can be found here
    • Thread Starter
    Offline

    0
    ReputationRep:
    (Original post by vanguardsean)
    This is part of try/catch statement, its purpose is to run the code in the "try" section; if an error occurs in the code, its looks at the "catch" sections. Here you have got two possible errors that it can catch:

    1) NumberFormatException --> This is an error that is thrown when you try to convert a string to an integer for example.

    2) IOException --> An error that is thrown is something goes with reading/writing to/from files, file permissions, disk space errors.

    If either of these errors occurs in the "try" of the try/catch statement, the code inside the "catch" section will run. In this case, an output will be displayed and the program will halt.

    Hopefully this helped.

    P.S: More information about Exception Handling can be found here
    This has helped A LOT!! Thank you very very much!
 
 
 
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • Poll
    What newspaper do you read/prefer?
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

    Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

    Quick reply
    Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.