Closed ErikSchierboom closed 4 years ago
The difficulty with pushing the student to use exceptions is that they can almost always be avoided with some sort of up front guard, e.g. TryParse
, testing for null
, index out of range, etc. Obviously IO is a fruitful area but I'm not sure how we are handling that in the exercises. I thought of overflow but we would have to give a hint up front about using checked
. I suppose that would work if we make the overflow concept/exercise a prerequisite.
Orthogonally to that issue I think we will need 2 tasks, 1 to instantiate and throw a new exception and one to catch it with appropriate filtering.
Comments please.
The difficulty with pushing the student to use exceptions is that they can almost always be avoided with some sort of up front guard
This is true, and I do think that we should mention this in an after.md
file. However, we can still teach students that they can define user-defined exceptions, only that they should only do so if other methods cannot be used. Something like that?
Obviously IO is a fruitful area but I'm not sure how we are handling that in the exercises. I thought of overflow but we would have to give a hint up front about using checked. I suppose that would work if we make the overflow concept/exercise a prerequisite.
IO has always been slightly problematic in exercise, so we tend to avoid it. The checked
overflow bits are part of the overflows
exercise (see this issue). I've also toyed with the idea of having overflows be part of the integral-numbers
exercise (see this issue). I think in this case we have to come up with some reasonable use case for exceptions, but we don't have to go overboard to make it 100% realistic I feel.
Orthogonally to that issue I think we will need 2 tasks, 1 to instantiate and throw a new exception and one to catch it with appropriate filtering.
Agreed.
I think in this case we have to come up with some reasonable use case for exceptions, but we don't have to go overboard to make it 100% realistic I feel.
I agree that there has to be a balance between realism and practicality. I wasn't sure what side of the debate about using the overflow/checked
mechanism to produce the initial exception you came down on.
My proposal is to include a pre-built method in the code template which causes an overflow exception. The student is asked to make sure that the method is called as part of some sort of maths library and a) handle the exception by wrapping / substituting their own exception and b) catch and handle their own exception.
Please let me know what you think.
a) handle the exception by wrapping / substituting their own exception and b) catch and handle their own exception.
Ooh, I like this! The catch-and-wrap addition is a great idea.
as part of some sort of maths library
Just a random thought on a theme: what if we would make it about doing calculations in software that runs on a space-bound rocket? Might give us some pretext to catch all possible exceptions, but do some special filtering for the specific overflow exception or something like that.
@mikedamay Would you envision this exercise introducing overflows, or have this depend on it being introduced in another exercise (like the integral-numbers
exercise)?
For inspiration: see Elixir's errors
exercise.
closed by #1617
This issue describes how to implement the
user-defined-exceptions
concept exercise for the C# track.Getting started
Please please please read the docs before starting. Posting PRs without reading these docs will be a lot more frustrating for you during the review cycle, and exhaust Exercism's maintainers' time. So, before diving into the implementation, please read up on the following documents:
Please also watch the following video:
Goal
The goal of this exercise is to teach the student the Concept of User-defined Exceptions in C#.
Learning objectives
Out of scope
Concepts
This Concepts Exercise's Concepts are:
user-defined-exceptions
: know how to define a user-defined exception.exception-filtering
: know how to use exception filtering.Any data types used in this exercise (e.g.
strings
) should also be added as prerequisites.Prequisites
This Concept Exercise's prerequisites Concepts are:
exceptions
: know how to work with exceptions.inheritance
: inheriting from theException
class for the custom exception.Resources to refer to
Hints
After
Representer
This exercise does not require any specific representation logic to be added to the representer.
Analyzer
This exercise does not require any specific analyzer logic to be added to the analyzer.
Implementing
To implement this exercise, please follow these instructions.
Help
If you have any questions while implementing the exercise, please post the questions as comments in this issue.