aboutsummaryrefslogtreecommitdiff
path: root/notes/async_exception_handling.txt
blob: 5a71d344d338d2569417a6806c1ec62831094f48 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

Handling asynchronous exceptions
================================

Limitations:

* Async exception handlers must NOT see program state (it may have been
  destroyed or in an inconsistent or "impossible" state).
* Exception handlers could be an additional `entry` in the service
  implementation. The exact behavior could vary between different service
  types.
* State that needs to be preserved could be stored in a `giveme`. It would
  either have to be "taken" (as a linear type) or it would have to be
  serialized. (Maybe that could be an implementation detail? Serialization
  could be the default, and pass-as-linear-type could be an optional
  optimization).
    - A linear/affine type would avoid bugs, where the programmer keeps the
      reference and thinks that updates to it would update the copied/
      serialized object.


Example code:

    giveme
        int param = param "-n"
        ErrorState! int current_step = defval 0
        MessageReporter! mr
    end

    entry main
    code
        current_step.set 1
        # could trigger a division by zero exception
        int i = 10 / param

        current_step.set 2
        int i = 10 / (param-1)
    end

    entry exception
    code
        # It should only be possible to access `giveme`s that have been
        # marked as exception safe. How to implement that in the language?
        # OR maybe require all non-constant `giveme`s to be exception-safe,
        # and NOT be able to generate exceptions themselves?
        mr.error "Failed at step {}" current_step.get
    end