exercism / exercism/csharp

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

Offen
#1,450 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
C#
Sterne
427
Forks
383
Ø Merge
2 T. 2 Std.
Gemergte PRs (30 T.)
5

Beschreibung

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

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.