Sponsored Links

Results 1 to 2 of 2

Thread: Why we are passing IndexOutOfBoundsException ex in catch?we have not ex.any Method or

  1. #1
    Senior Member saneha's Avatar
    Join Date
    Apr 2011

    Adrive2 Why we are passing IndexOutOfBoundsException ex in catch?we have not ex.any Method or

    Sponsored Links

    Here in code
    catch(IndexOutOf BoundsException ex){
    System.out.println(“you forget the passing parameters”);
    we have method catch having the parameter of class IndexOutOfBoundsException ex, here ex is an identifier (or instance of the object)of IndexOutOfBoundsException.
    Every object of class has Private ,public, protected parts which can be access public or protected parts with the help of identifier like ex, but in the above method, we are not using the ex to access the any part of object or instance of the class IndexOutOfBoundsException.like ex . anyMethod(getter or setter or other method of the class)
    Then if I donot use ex to access any part with help of “.” , then why passing temporary object as a parameter? Why we need it ? where its role in the code?

    Sponsored Links

  2. Sponsored Links
  3. #2
    Administrator Vuhelper's Avatar
    Join Date
    Apr 2011
    Each catch block is an exception handler and handles the type of exception indicated by its argument. The argument type, ExceptionType, declares the type of exception that the handler can handle and must be the name of a class that inherits from the Throwable class. The handler can refer to the exception with name.

    In this code we are handling IndexOutOf BoundsException , Although we are not using any method of this but as it is required by catch so we are passing this argument.

    You can use ex to display details of the exception like

    catch(IndexOutOf BoundsException ex){
    System.out.println(“you forget the passing parameters”);



    In simple words we have to pass this argument as this is the requirement, this argument will tell compiler that what type of exception that will handle.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. VU passing criteria
    By amina9malik in forum Assignments & Solutions
    Replies: 1
    Last Post: 01-27-2014, 10:05 PM
    By viki in forum Announcements
    Replies: 2
    Last Post: 05-21-2012, 03:46 PM
  3. Passing 2d array by reference June 2011
    By Vuhelper in forum C++ Programing
    Replies: 0
    Last Post: 06-19-2011, 06:11 PM
  4. Replies: 1
    Last Post: 04-28-2011, 09:12 PM
  5. try, catch and finally block?
    By saneha in forum Java forum
    Replies: 0
    Last Post: 04-24-2011, 07:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
-: Vuhelp Disclaimer :-
None of the files shown here are hosted or transmitted by this server. The links are provided solely by this site's users. The administrator's or staff of Vuhelp.net cannot be held responsible for what its users post, or any other actions of its users. You may not use this site to distribute or download any material when you do not have the legal rights to do so. It is your own responsibility to adhere to these terms. If you have any doubts about legality of content or you have any suspicions, feel free to contact us.
Online Education | JhelumSoft