diff options
author | Sudipto Mallick <smlckz@termux-alpine> | 2024-01-28 06:38:55 +0000 |
---|---|---|
committer | Sudipto Mallick <smlckz@termux-alpine> | 2024-01-28 06:38:55 +0000 |
commit | fc4d96a9e3e20f8ddf035c16fc32b1effb75481b (patch) | |
tree | 4e13b2606e94e2098d1a288b051603cfc36d983b /java/text/CustomExceptionExample.typ | |
parent | cd6a9243c056710794549a1ab5d51fbdd082ce2e (diff) | |
download | zadania-fc4d96a9e3e20f8ddf035c16fc32b1effb75481b.tar.gz |
Complete all Java assignments
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() |