Excpetions , Multiple Exceptions , how ??
Virtual Position Forum :: Members Lounge :: Sciences & Knowledge :: Programing and Design :: Java Forum
Page 1 of 1 • Share
Excpetions , Multiple Exceptions , how ??
Sir, I got a question , how to throw multiple exceptions form a method , and how we could know that , on a particular event , a specific kind of exception will be generated ,
for example we take input form user , and user don't write anything , what kind of the exception will be generated from here. and in the same method there is a chance of another exception like we try to open a file which don't exist , in this case there will be a total chance of two exceptions, One will be IO related, what will be the other ?????. This is just a case I think in different cases there will be different kind of exceptions. How can we know all them??
e.g.
public void method()
{
String str ;// A Null point exception
//assume user don't enter any input in the field ...there will be another exception.
str =JOptionPane.showInputDialog(null, "Please enter input. ");
dobule dAge ;
dAge= Double.parseDouble(JoptionPane.showInputDialog(nul l, "Please enter your age. "))//assume user enter his age in the form of String "like twenty instead of 20”. Here, another exception will be generated.
}
Now my question is how can we throw all these exceptions , how can we figure out that what kind of exception will be generated and how can we catch them ????
Thanks ….
for example we take input form user , and user don't write anything , what kind of the exception will be generated from here. and in the same method there is a chance of another exception like we try to open a file which don't exist , in this case there will be a total chance of two exceptions, One will be IO related, what will be the other ?????. This is just a case I think in different cases there will be different kind of exceptions. How can we know all them??
e.g.
public void method()
{
String str ;// A Null point exception
//assume user don't enter any input in the field ...there will be another exception.
str =JOptionPane.showInputDialog(null, "Please enter input. ");
dobule dAge ;
dAge= Double.parseDouble(JoptionPane.showInputDialog(nul l, "Please enter your age. "))//assume user enter his age in the form of String "like twenty instead of 20”. Here, another exception will be generated.
}
Now my question is how can we throw all these exceptions , how can we figure out that what kind of exception will be generated and how can we catch them ????
Thanks ….
Diya- Monstars
-
Posts : 364
Join date : 2011-02-08
Age : 32
Character sheet
Experience:
(10/500)
Re: Excpetions , Multiple Exceptions , how ??
You can throw multiple exceptions as follows
public void method() throws IOException, NullPointerException //so on you can add as many as you want or require and this will be handled in caller //function
{
String str ;// A Null point exception
//assume user don't enter any input in the field ...there will be another exception.
str =JOptionPane.showInputDialog(null, "Please enter input. ");
double dAge ;
dAge= Double.parseDouble(JoptionPane.showInputDialog(nul l, "Please enter your age. "))//assume user enter his age in the form of String "like twenty //instead of 20”. Here, another exception will be generated.
}
IOException can catch all type of exceptions.
public void method() throws IOException, NullPointerException //so on you can add as many as you want or require and this will be handled in caller //function
{
String str ;// A Null point exception
//assume user don't enter any input in the field ...there will be another exception.
str =JOptionPane.showInputDialog(null, "Please enter input. ");
double dAge ;
dAge= Double.parseDouble(JoptionPane.showInputDialog(nul l, "Please enter your age. "))//assume user enter his age in the form of String "like twenty //instead of 20”. Here, another exception will be generated.
}
IOException can catch all type of exceptions.
Vuhelper- Deep Bench
- Posts : 97
Join date : 2011-05-29
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