Virtual Position Forum
Please register to watch content in detail
Thanks
Admin virtual position


Join the forum, it's quick and easy

Virtual Position Forum
Please register to watch content in detail
Thanks
Admin virtual position
Virtual Position Forum
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Excpetions , Multiple Exceptions , how ??

View previous topic View next topic Go down

GMT + 3 Hours Excpetions , Multiple Exceptions , how ??

Post by Diya Sun May 29, 2011 3:15 pm

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 ….
Diya
Diya
Monstars
Monstars

Taurus Goat
Posts : 364
Join date : 2011-02-08
Age : 32
Notworthy

Character sheet
Experience:
Excpetions , Multiple Exceptions , how ?? Left_bar_bleue10/500Excpetions , Multiple Exceptions , how ?? Empty_bar_bleue  (10/500)

Back to top Go down

GMT + 3 Hours Re: Excpetions , Multiple Exceptions , how ??

Post by Vuhelper Sun May 29, 2011 3:16 pm

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.
avatar
Vuhelper
Deep Bench
Deep Bench

Posts : 97
Join date : 2011-05-29

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

Permissions in this forum:
You cannot reply to topics in this forum