Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Invalid Command Line Arguments Exception

Is there an appropriate exception class for invalid command line arguments in the Java API or do I have to create my own? I've tried searching for one but can't find any in the API.

This is for an assignment so I cannot use third party libraries for command line parsing.

like image 288
Michael Avatar asked Aug 31 '12 02:08

Michael


People also ask

How do you check if there are command line arguments in Java?

We can check these arguments using args. length method. JVM stores the first command-line argument at args[0], the second at args[1], the third at args[2], and so on.

Can Java take command line arguments?

A Java application can accept any number of arguments from the command line. This allows the user to specify configuration information when the application is launched. When an application is launched, the runtime system passes the command-line arguments to the application's main method via an array of String s.

What is Java command line arguments?

Java command line arguments are arguments that are passed to your program via a terminal or shell command. They make your Java program more configurable by giving users or scripts running your software a way to specify input parameters at run time.


1 Answers

Most of the times, when the received argument(s) are invalid, it's a common idiom to throw an IllegalArgumentException.

public class IllegalArgumentException extends RuntimeException

Thrown to indicate that a method has been passed an illegal or inappropriate argument.

like image 124
João Silva Avatar answered Oct 13 '22 22:10

João Silva