added exception handling

This commit is contained in:
marco committed 2026-08-31 13:43:43 +02:00
1 parent ffb308dc52
commit 5b64b32721
2 files changed
+18 -11

No files matched your search

+3 -4
View File
@@ -24,10 +24,9 @@ public sealed class Person
realName = realName.Trim();
// TODO: Error Handling
if (username.Length is < 3 or > 32) throw new Exception();
if (realName.Length == 0) throw new Exception();
if (birthday >= DateOnly.FromDateTime(DateTime.Today)) throw new Exception();
if (!IsAtLeast16(birthday)) throw new Exception();
if (username.Length is < 3 or > 32) throw new ArgumentException("Username must be 3-32 chars.");
if (realName.Length == 0) throw new ArgumentException("Name cannot be empty");
if (!IsAtLeast16(birthday) || birthday >= DateOnly.FromDateTime(DateTime.Today)) throw new ArgumentException("Person must be at least 16 years old.");
return new Person(username, realName, birthday);
}