Complete the method so that the number num
is set to index point index
in the array named array
. Be sure to handle the exception with the...
Search Results
Searching for: Exception Handling
Individual Exercises
Surround the appropriate lines of code with a try catch block so that first, an exception is caught when the String index is out of...
Create a method that returns the third character from the String word
. Be sure to use a try catch block and use the appropriate exception...
Considering the following lines of code, what will be the output?
try { String str = null; System.out.println(str.charAt(0)); }...
A string is a palindrome if it reads the same forward and backward, with case insensitivity. For example, the words "mom", "dad", "Mom",...
The following method takes in a list of generic objects and returns the number of items in the list. As written, however, the method will...
The method below takes in two integers as parameters and should throw an IllegalArgumentException
if either parameter is the number 5. In...
The method below takes an array of Jeroos and should throw an exception if any Jeroo in the array is null
or if any is facing North.
In...
The method below takes in a String parameter representing a username. It should throw an Exception
if the username is less than 3...
The method divideValues()
will throw an IllegalArgumentException
if either parameter is 5. The method below takes two integer values as...
The validateJeroo()
method takes in an array of Jeroo objects and could throw two different exceptions.
If a Jeroo in the array is null,...
The following code runs a method called validateUser()
that will throw an IllegalArgumentException
if a username (passed in as a...
In the following code, which line will produce an error?
public class Answer { int[] nums = new int[5]; // Line 1 nums[0] = 1000000; //...
"Determine which exception is needed for each case and put them in the corresponding catch statement with the appropriate variable. Do ...
For the question below, assume the following implementation of a Person class:
public class Person { private int age; private String...
For the question below, assume the following implementation of a Person class:
public class Person { private int age; private String...
For the question below, assume the following implementation of a Person class:
public class Person { private int age; private String...
For the question below, assume the following implementation of an Employee class:
class Employee { String name; public Employee(String ...