Skip to content

Conversation

@TwitchBronBron
Copy link
Member

@TwitchBronBron TwitchBronBron commented Sep 26, 2024

Our current CatchStatement stores the exception variable as a Token. This PR converts the CatchStatement.exceptionVariable property to an Expression, which supports VariableExpression and TypeCastExpression. This should more closely align with how TypeScript supports catch(e as <any type you want here>). This was a breaking change to the AST, so it needed to be done as part of v1.0.0

Also supports completely omitting the exception variable when you don't need to use it.

function init()
    try
        somethingDangerous()
    catch
        print "I live on the edge"
    end try
end function

transpiles to

function init()
    try
        somethingDangerous()
    catch e ' or __bsc_error if there's a local variable conflict
        print "I live on the edge"
    end try
end function

@TwitchBronBron TwitchBronBron merged commit 8f75b92 into release-1.0.0 Sep 26, 2024
@TwitchBronBron TwitchBronBron deleted the catch-var-as-expression branch September 26, 2024 12:38
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.

3 participants