Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Custom Exception for Business Rules | Custom Exceptions and Guard Clauses
C# Exceptions and Error Handling Practice

bookChallenge: Custom Exception for Business Rules

Task

Swipe to start coding

Create a custom exception and use it to enforce a business rule in a banking scenario. Your goal is to prevent negative deposit amounts by throwing a custom exception when such an attempt is made.

  • Throw a NegativeDepositException if the amount passed to the Deposit method is less than zero.
  • Do not change the account balance if the exception is thrown.
  • If the deposit is valid, add the amount to the account balance.

Solution

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 2. Chapter 2
single

single

Ask AI

expand

Ask AI

ChatGPT

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

close

bookChallenge: Custom Exception for Business Rules

Swipe to show menu

Task

Swipe to start coding

Create a custom exception and use it to enforce a business rule in a banking scenario. Your goal is to prevent negative deposit amounts by throwing a custom exception when such an attempt is made.

  • Throw a NegativeDepositException if the amount passed to the Deposit method is less than zero.
  • Do not change the account balance if the exception is thrown.
  • If the deposit is valid, add the amount to the account balance.

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 2
single

single

some-alt