Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare that the method may throw an exception.
Java
public void readFile() [1] IOException { } Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using 'throw' instead of 'throws' in method declaration
Misspelling the keyword
Placing the keyword inside the method body
β Incorrect
The throws keyword declares that a method might throw an exception.
2fill in blank
mediumComplete the method declaration to indicate it throws multiple exceptions.
Java
public void process() [1] IOException, SQLException { } Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using 'throw' instead of 'throws'
Separating exceptions with semicolons instead of commas
Omitting the keyword entirely
β Incorrect
The throws keyword can list multiple exceptions separated by commas.
3fill in blank
hardFix the error in the method declaration that incorrectly uses the throws keyword.
Java
public void save() [1] IOException { } Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using 'throw' instead of 'throws'
Misspelling the keyword
Placing the keyword inside the method body
β Incorrect
The correct keyword to declare exceptions is throws, not throw.
4fill in blank
hardComplete the code to declare a method that throws two exceptions.
Java
public void connect() [1] IOException, SQLException { } Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using 'throw' instead of 'throws'
Separating exceptions with semicolons
Repeating the keyword before each exception
β Incorrect
Use throws once, then separate exceptions with a comma.
5fill in blank
hardComplete the code to declare a method throwing three exceptions correctly.
Java
public void execute() [1] IOException, SQLException, NullPointerException { } Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using multiple 'throws' keywords
Separating exceptions with semicolons
Using 'throw' instead of 'throws'
β Incorrect
Use throws once, then separate all exceptions with commas.