exercism / exercism/csharp

user-defined-exceptions - refactor code to illustrate concept more clearly

Open
#1,450 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
427
Forks
383
Avg merge
2d 2h
Merged PRs (30d)
5

Description

The [user-defined-exception](https://github.com/exercism/v3/tree/master/languages/csharp/exercises/concept/user-defined-exceptions) exercise has a story in which we are using a test harness to test a calculator by calling its `Multiply()` method. See this [example](https://github.com/exercism/v3/blob/master/languages/csharp/exercises/concept/user-defined-exceptions/.meta/Example.cs).

We are attempting to show two concepts: `user-defined-exceptions`/wrapping an exception and `exception-filtering`.

There are currently 2 methods in the `CalculatorTestHarness` class `TestMultiplication` and `Multiply`) which do similar things (one calls the other) as well as a method also called `Multiply()` in the `Calculator` class. The existence of 3 such similar sounding routines is confusing so refactoring is in order.

If we remove the `Multiply()` method from `CalculatorTestHarness` and move its `try-catch` block into the `Calculator.Multiply()` method (putting the `checked` multiplication into the `try` block then it will make more sense. e.g.:

```csharp
public class Calculator
{
public int Multiply(int x, int y)
{
try
{
checked
{
return x * y;
}
}
catch (OverflowException ofex)
{
// TODO: implement catch block
}

return 0; // TODO: remove this statement when implemented the catch logic
}
}
```

Changes will be required to:
- instructions.md
- hint.md
- Example.cs
- UserDefinedExceptions.cs
- UserDefinedExceptionsTest.cs

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.