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 : 33
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
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