Why we are passing IndexOutOfBoundsException ex in catch?we have not ex.any Method or
Virtual Position Forum :: Members Lounge :: Sciences & Knowledge :: Programing and Design :: Java Forum
Page 1 of 1 • Share
Why we are passing IndexOutOfBoundsException ex in catch?we have not ex.any Method or
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?
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?
Diya- Monstars
-
Posts : 364
Join date : 2011-02-08
Age : 32
Character sheet
Experience:
(10/500)
Re: Why we are passing IndexOutOfBoundsException ex in catch?we have not ex.any Method or
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”);
System.out.println(ex.getMessage());
}
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.
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”);
System.out.println(ex.getMessage());
}
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.
Vuhelper- Deep Bench
- Posts : 97
Join date : 2011-05-29
Similar topics
» flush method in java 2011
» 20% Rule for passing an Exam
» try, catch and finally block?
» Guards catch prisoner in Mexico suitcase jailbreak
» The study method
» 20% Rule for passing an Exam
» try, catch and finally block?
» Guards catch prisoner in Mexico suitcase jailbreak
» The study method
Virtual Position Forum :: Members Lounge :: Sciences & Knowledge :: Programing and Design :: Java Forum
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
Sat May 04, 2024 11:49 am by ali001
» house disrepair claims
Thu May 02, 2024 4:29 pm by Ibad Khan Buledi
» Bounce n Bang: Physics puzzler
Thu May 02, 2024 11:39 am by ali001
» AIChatSY - AIChatbot Assistant
Wed May 01, 2024 10:48 am by ali001
» Storybook Magic App
Tue Apr 30, 2024 7:06 pm by ali001
» Flower Book Match3 Puzzle Game
Tue Apr 30, 2024 12:17 pm by ali001
» Avian Influenza Symptom in Chickens "Bird Flu H5N1 Virus" Vet learning materials, Poultry Farming
Sat Apr 27, 2024 9:57 am by Ibad Khan Buledi
» Aloha Planner - Note-Taker
Thu Apr 11, 2024 4:52 pm by ali001
» Streaming Guide Film TV Series
Tue Apr 09, 2024 9:39 pm by ali001