Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Guard Clauses in User Registration | Custom Exceptions and Guard Clauses
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
C# Exceptions and Error Handling Practice

bookChallenge: Guard Clauses in User Registration

Task

Swipe to start coding

Write a method to register a user that uses guard clauses to validate the provided username and password.

  • If username is null or empty, immediately throw an ArgumentException with the message "Username cannot be null or empty.".
  • If password is null or empty, immediately throw an ArgumentException with the message "Password cannot be null or empty.".
  • If both inputs are valid, return a string in the format "User '' registered successfully.".

Solution

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 2. ChapterΒ 4
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

close

bookChallenge: Guard Clauses in User Registration

Swipe to show menu

Task

Swipe to start coding

Write a method to register a user that uses guard clauses to validate the provided username and password.

  • If username is null or empty, immediately throw an ArgumentException with the message "Username cannot be null or empty.".
  • If password is null or empty, immediately throw an ArgumentException with the message "Password cannot be null or empty.".
  • If both inputs are valid, return a string in the format "User '' registered successfully.".

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 2. ChapterΒ 4
single

single

some-alt