Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

khchen
Copy link

@khchen khchen commented Jul 4, 2022

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
  * 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