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

[RFC] Error Handling #82

Open
mertyildiran opened this issue Dec 16, 2020 · 0 comments
Open

[RFC] Error Handling #82

mertyildiran opened this issue Dec 16, 2020 · 0 comments
Assignees
Labels
feature request New feature or request
Projects

Comments

@mertyildiran
Copy link
Member

mertyildiran commented Dec 16, 2020

Implement error handling using the decision block and catch statement. This feature will also require implementing a core library named errors to fetch the error code. The syntax will look like this:

from errors import index_out_of_range

num def return_zero()
    num r = 0
    retun r
end

num def return_first(num list a)
    num r = a[0]
    retun r
end {
    catch index_out_of_range() : return_zero()
}

num def get_index_of_using_sum(num list a, num x, num y)
    num z = x + y
    num r = a[z]
    return r
end {
    catch index_out_of_range() : return_first(a)
}

print get_index_of_using_sum([1, 2, 3, 4, 5], 1, 4) # Should print 1

print get_index_of_using_sum([], 1, 1) # Should print 0

In that way, one can implement his/her own function to return the desired error code instead of using the errors library:

num def index_out_of_range()
    num r = 8
    return r
end

num def return_zero()
    num r = 0
    retun r
end

num def return_first(num list a)
    num r = a[0]
    retun r
end {
    catch index_out_of_range() : return_zero()
}

num def get_index_of_using_sum(num list a, num x, num y)
    num z = x + y
    num r = a[z]
    return r
end {
    catch index_out_of_range() : return_first(a)
}

print get_index_of_using_sum([1, 2, 3, 4, 5], 1, 4) # Should print 1

print get_index_of_using_sum([], 1, 1) # Should print 0
@mertyildiran mertyildiran added the feature request New feature or request label Dec 16, 2020
@mertyildiran mertyildiran self-assigned this Dec 16, 2020
@mertyildiran mertyildiran added this to To do in Chaos via automation Dec 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
Chaos
  
To do
Development

No branches or pull requests

1 participant