← Back to Exceptions
Question 747
Custom Exception With Data
Custom Exception With Data
Define a custom exceptionNegativeNumberExceptionthat stores the rejected number in anint Valueproperty. Read an integern. Ifn < 0, throw the exception passingn; otherwise printAccepted: <n>. In the catch, printRejected: <ex.Value>. Declare the class after the top-level statements. Input7prints: Accepted: 7 Input-4prints: Rejected: -4
Expected Output:
Accepted: 7= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
Exceptions
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cw, cr, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.