Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
ascendbatch2025
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Bhargavi Ghanta
ascendbatch2025
Commits
bb573060
Commit
bb573060
authored
Jun 10, 2025
by
Bhargavi Ghanta
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated AgeValidator and ExceptionClass with latest changes
parent
a691cd74
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
0 deletions
+39
-0
AgeValidator.java
src/AgeValidator.java
+33
-0
ExceptionClass.java
src/ExceptionClass.java
+6
-0
No files found.
src/AgeValidator.java
0 → 100644
View file @
bb573060
public
class
AgeValidator
{
// Method to validate age
public
static
void
validateAge
(
int
age
)
{
try
{
if
(
age
<=
0
)
{
throw
new
InvalidAgeException
(
"Age must be greater than 0. Invalid input: "
+
age
);
}
else
{
System
.
out
.
println
(
"Valid age: "
+
age
);
}
}
catch
(
InvalidAgeException
e
)
{
throw
e
;
// Rethrow so it can be caught in main
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"Unexpected error in validateAge: "
+
e
.
getMessage
());
}
}
// Main Method
public
static
void
main
(
String
[]
args
)
{
int
[]
testAges
=
{
95
,
-
67
,
-
20
,
-
12
,
-
32
,
-
58
,
98
,
12
,
3
,
15
};
// Test cases
for
(
int
age
:
testAges
)
{
try
{
validateAge
(
age
);
}
catch
(
InvalidAgeException
iae
)
{
System
.
out
.
println
(
"Caught InvalidAgeException: "
+
iae
.
getMessage
());
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"Caught General Exception: "
+
e
.
getMessage
());
}
}
}
}
\ No newline at end of file
src/ExceptionClass.java
0 → 100644
View file @
bb573060
// Custom Exception Class
class
InvalidAgeException
extends
RuntimeException
{
public
InvalidAgeException
(
String
message
)
{
super
(
message
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment