Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
java programming?
how do i go about fixing this so it will compile?
class Exception1
{
public static void main(String[] args)
{
if (Integer.parseInt(args[0]) == 0)
throw new Exception("Invalid Command Line Argument");
}
}
2 Answers
- 7 years ago
class Exception1
{
public static void main(String[] args) throws Exception
{
if (args.length == 0)
throw new Exception("Invalid Command Line Argument");
}
}
Remember that ur args array is empty
- 7 years ago
/******Method 1 :******/
public class Exception1
{
public static void main(String[] a) throws Exception
{
/*
Integer.parseInt(a[0]) this line throw exception so you have to use throws Exception or put it in try catch block */
if (Integer.parseInt(a[0]) == 0)
throw new Exception("Invalid Command Line Argument");
}
}
/******Method 2 :******/
public class Exception1
{
public static void main(String[] a)
{
try
{
if (Integer.parseInt(a[0]) == 0)
throw new Exception("Invalid Command Line Argument");
}
}
catch(Exception e){}
}