0
Can anybody help me with error handling in java?
I have to use the defensive coding to validate the arguments that are given with command prompt
4 Answers
+ 2
Ok first clearly illustrate ur prblm than only i can help.
+ 1
Use comparing your string objects (their reference variables) with null to figure out if the action you are about to make is valid, if not - exit the program.
0
Okay,thanks first
I have to call three different commands with arguments in this way:
If(args[0].equal("some text")
{ string str=args[1];
If(args[1].equal("exmp."word")
Then call the method to count words.
And the problem is that we have to use defensive programming to throw errors without try catch for example if there is missing arg[0] we have to throw a message and close the program with exit.code
0
if your are passing file name as arguments then declare main method to handle Fileexception as
public static void main(String args[]) throws FileNotFoundException
If it missing elements, then use NosuchElementexistsException
If number mismatch, then use NumberFarmatException