โ Back to Exceptions
Question 657
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
Topics:
Exceptions
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท 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.