QUESTION IMAGE
Question
what should you place in the blank in the following code to enable the program to handle errors that occur when the calculatereward() method executes?
start
try
calculatereward()
endtry
______
// the program continues
stop
a declarations
exception e = new exception()
throw e
b. catch
exception e = new exception()
output \oops! something went wrong.\
endcatch
c. catch(exception e)
output \oops! something went wrong.\
endcatch
d. code to create a basic exception class
To handle errors in a try block, a catch block is needed. Option a re - throws the exception without proper handling. Option b's catch syntax is incorrect as it tries to declare the exception inside the catch block in a non - standard way. Option d is about creating an exception class, not handling the error from calculateReward(). Option c has the correct catch syntax with a parameter to catch the exception and then outputs an error message, which is the proper way to handle the error from the try block.
Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
c. catch(Exception e)
output "Oops! Something went wrong."
endcatch