+ 1
When is io exception used in java?
6 Answers
+ 1
when ever u want.
its just ur choice .
suppose u want user to restrict on input integer values.
so whenever he/she types float values or char values u throw io exception
+ 1
int x = 1/0; = infinite......... u can't print infinite.......so this is Arithmetic Exception
+ 1
To avoid unexpected results, termination etc. Suppose you made a program to store and retrieve info on family members, in a graph like or some other way. You want to add a new member to your family. A baby just born so an official name has to wait. You enter birthday, fathers name, mother name. But you made your database to have key name and DOB. Your program asks database to add a member but database tells no way sir. Control comes back to Java program and it cannot move forward, it has no other option other than execute addToDataBase instruction. So your program is stuck on an instruction and it has no going forward. What your Database did is throw an exception. I cannot add a field without a key.
Such things happen and that's where exception handling plays a role.
+ 1
Thanx evry1...ths really helped
0
for example:
You want people to type the days of the week (it's 7 days, from 1 to 7) and it turns out they wrote 9, it's not a valid value, so you use an exception.
- 1
You can use it when you reads/writes files.