diff options
Diffstat (limited to 'java/text/CustomExceptionExample.typ')
-rw-r--r-- | java/text/CustomExceptionExample.typ | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/java/text/CustomExceptionExample.typ b/java/text/CustomExceptionExample.typ new file mode 100644 index 0000000..4b653e8 --- /dev/null +++ b/java/text/CustomExceptionExample.typ @@ -0,0 +1,23 @@ +#import "/template.typ": * +#show: A => apply(A) +#set raw(lang: "java-new") +#set par(leading: 0.75em) + +#assignment(24, block: true)[ + Write a program that prompts the user for an integer input, and if the entered value is less than zero, throw a custom exception; additionally, handle exceptions for input of non-integer data types. +] + +#scos("CustomExceptionExample") + +=== Discussion + +#skind[Classes and methods implemented in the program] + +- Class `NegativeNumberException` (extends `Exception`): Custom exception class for negative numbers. + - Constructor `public NegativeNumberException(String)`: Constructs an Exception object to be thrown using the provided message string. + +- Main program: + - Class `CustomExceptionExample`: + - `public static void main(String[])`: Contains the main program demonstrating custom exception handling for negative numbers and handling input mismatches. + +#signature() |