Can anybody help me with error handling in java? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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 🇮🇳