Skip to content

[Enhancement] add experimental error handling: Fiber.try() and built-in raise()#269

Open
khchen wants to merge 4 commits into
ThakeeNathees:masterfrom
khchen:try
Open

[Enhancement] add experimental error handling: Fiber.try() and built-in raise()#269
khchen wants to merge 4 commits into
ThakeeNathees:masterfrom
khchen:try

Conversation

@khchen

@khchen khchen commented Jul 4, 2022

Copy link
Copy Markdown

Basic error handling via fiber. Example:

fb = Fiber fn
  [][1]
end

fb.try()
if fb.error
  print(fb.error)
else
  print("OK")
end

Output:

List index out of bound.

Also fix following bug:

1.times fn (i)
  1.times fn (i)
    [][1]
  end
end
assert(false) # should be unreachable

Output before this patch:

Error: List index out of bound.
  @func() [/workspace/pocketlang/build/test.pk:3]
Error: Assertion failed.
  @main() [/workspace/pocketlang/build/test.pk:6]

After this patch:

Error: List index out of bound.
  @func() [/workspace/pocketlang/build/test.pk:3]
  @func() [/workspace/pocketlang/build/test.pk:4]
  @main() [/workspace/pocketlang/build/test.pk:5]

Traditional try, except, finally can be emulated. Example: tests/lang/try.pk.

@khchen khchen changed the title add experimental error handling: Fiber.try() and built-in raise(). [Enhancement] add experimental error handling: Fiber.try() and built-in raise() Jul 18, 2022
khchen added 2 commits July 29, 2022 09:52
  * add pkSetRuntimeErrorObj and pkGetRuntimeError
  * pkSetRuntimeError can accept NULL to reset the error.
  * functions with "return !VM_HAS_ERROR(vm)" should reset the error at first.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant