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 : 33
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
Yesterday at 12:21 pm by ali001
» Hemangiom'App
Tue Nov 05, 2024 11:25 am by ali001
» MindfulMe - Mental Health App
Mon Nov 04, 2024 10:50 am by ali001
» Learn Candlestick Patterns
Tue Oct 15, 2024 5:51 am by ali001
» Woh Pagal Si Episode 52 to 62 - Top Pakistani Drama
Sat Sep 21, 2024 6:26 pm by Mir Emmad Ali Khan Domki
» Nearu - share your socials
Sat Sep 21, 2024 1:12 pm by ali001
» Nightclub Tycoon: Idle Empire
Thu Sep 19, 2024 9:16 pm by ali001
» Carnivore - Meat Diet Recipes
Wed Sep 18, 2024 2:37 pm by ali001
» Eid Milad un Nabi Mubarak 2024 (Rabiʻ I 14, 1446 AH)
Tue Sep 17, 2024 3:44 pm by Mir Emmad Ali Khan Domki