Search the courses, subjects, tracks, games and features, or jump straight to a page.
2 cards from this section. Quick, good the night before a test.
What is the purpose of the 'throw' keyword in Java?
Think about how you might signal that something has gone wrong in your program.
Write a line of code using the 'throw' keyword to indicate a division by zero error.
Remember the exception type associated with arithmetic operations.
What does the 'throw' keyword do in Java?
It’s about signaling errors.
True or False: The 'throw' keyword can be used in a method declaration.
Think about where you place the keywords.
Design a simple application that prompts a user for their age and throws a custom exception if the age is less than a defined threshold (e.g., 18).
Think about how you’d communicate age restrictions.
Write a method that calculates the square root of a number and throws an exception if the input number is negative.
What happens with negative numbers in square roots?
5 more questions in this section. Enroll free to practise them all.
Enroll free