exercism / exercism/go

Implement new Concept Exercise: panic-recover

Open
#1,373 13 comments 0 reactions 1 assignee Claimed by @myworkcircle View on GitHub
x:action/create x:knowledge/intermediate x:module/concept-exercise x:size/large x:status/claimed x:type/content
Dominant language
Go
Stars
1.2k
Forks
686
Avg merge
54m
Merged PRs (30d)
1

Description

This issue describes how to implement the `panic-recover` concept exercise for the Go track.

## Getting started

The docs can be found here
- [What are Concept Exercises?](https://exercism.org/docs/building/product/concept-exercises)
- [Concept Exercises](https://exercism.org/docs/building/tracks/concept-exercises)
- [Concepts](https://exercism.org/docs/building/tracks/concepts)

Also, be aware of these general guidelines:

- [Exercism Markdown Specification](https://exercism.org/docs/building/markdown/markdown)
- [Exercism Formatting and Style Guide](https://exercism.org/docs/building/markdown/style-guide)

## Goal

The goal of this exercise is to teach the student how to work with `panic` and `recover` in Go.

## Learning objectives

- `panic` with error or other value
- `recover` a panic
- check the value type of the recover value
- `don't panic`: if, then only in `main` package to crash the program (e.g. if not all required services are reachable)
- other things that can panic: nil pointer dereference, index out of bounds, etc.
- A panic in the code is always a bug --> fix it! (don't use it as `try .. catch` alternative!)
- global panic handling in e.g. web-servers: their reason is to prevent potential bugs from crashing the entire server

## Out of scope

Nothing yet.

## Concepts

- `panic-recover`

## Prerequisites

- `defer`
- `type-assertions`

## Resources to refer to

- https://blog.golang.org/defer-panic-and-recover

## Implementing

Some function(s) that panic and the panic must be recovered in another function and turned into a proper error.

As an idea on how to teach "when not to use a panic/not to handle a panic but instead fix the bug":
Some functions could be already in the stub that panic on running the tests and the students task is to fix the problem. (they should fix the bug, not use `recover`)

## Help

If you have any questions while implementing the exercise, please post the questions as comments in this issue.

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.