exercism / exercism/csharp

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

Abierto
#1,450 0 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
C#
Estrellas
427
Forks
383
Merge medio
2 d 2 h
PR fusionados (30 d)
5

Descripción

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

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.