exercism / exercism/csharp

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

Aperta
#1,450 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
C#
Stelle
427
Fork
383
Merge medio
2g 2h
PR unite (30g)
5

Descrizione

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

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.