0
0
Javaprogramming~10 mins

Throws keyword in Java - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
Athrow
Bthrows
CthrowsException
DthrowsError
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using 'throw' instead of 'throws' in method declaration
Misspelling the keyword
Placing the keyword inside the method body
2fill in blank
medium

Complete 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'
Athrow
BthrowsException
Cthrows
DthrowsError
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using 'throw' instead of 'throws'
Separating exceptions with semicolons instead of commas
Omitting the keyword entirely
3fill in blank
hard

Fix 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'
Athrows
BthrowsError
CthrowsException
Dthrow
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using 'throw' instead of 'throws'
Misspelling the keyword
Placing the keyword inside the method body
4fill in blank
hard

Complete 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'
Athrows
B,
C;
Dthrow
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using 'throw' instead of 'throws'
Separating exceptions with semicolons
Repeating the keyword before each exception
5fill in blank
hard

Complete 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'
Athrows
B,
C;
Dthrow
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using multiple 'throws' keywords
Separating exceptions with semicolons
Using 'throw' instead of 'throws'