summary refs log tree commit diff stats
path: root/java/text/CustomExceptionExample.typ
blob: 4b653e8a3e36583be9c5f9ae6f6eec3745481f3f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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()