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

28th Mar 2020, 6:56 PM
Florentina Ƈela
Florentina Ƈela - avatar
4 Answers
+ 2
Ok first clearly illustrate ur prblm than only i can help.
28th Mar 2020, 7:45 PM
Piyush Srivastava
Piyush Srivastava - avatar
+ 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.
29th Mar 2020, 1:38 AM
Š„Š¾Š¼ŃŃ‡Šµ ŠŠµŠ²Š°Š¶Š½Š¾
Š„Š¾Š¼ŃŃ‡Šµ ŠŠµŠ²Š°Š¶Š½Š¾ - avatar
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
29th Mar 2020, 1:29 AM
Florentina Ƈela
Florentina Ƈela - avatar
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
29th Mar 2020, 6:07 PM
Jayakrishna šŸ‡®šŸ‡³