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

error handling - finally block #70

Open
delasy opened this issue Apr 21, 2023 · 2 comments
Open

error handling - finally block #70

delasy opened this issue Apr 21, 2023 · 2 comments
Assignees
Labels
design This issue or pull request is related to design change enhancement New feature or request

Comments

@delasy
Copy link
Member

delasy commented Apr 21, 2023

I was implementing Error Handling, and I didn't find a good solution for FINALLY statement. I would like to have it but can't find a solution. I will leave it open for people coming across, the only solution I can find is this, the problems it has, with FINALLY not going to be executed when:

  1. return in try or catch blocks
  2. at exit

If someone has ideas how to implement it feel free to share down below.
Current codegen for try/catch looks like this (it's not exact but just to give you the idea):

switch (setjmp(jmp_buf)) {
  case 0: {
    // try body
    break;
  }
  case 31: { // catch err: error_Error
    // catch body
    break;
  }
  case 35: { // catch err: ErrorCustom
    // catch body
    break;
  }
  default: { // Unhandled Error
    break;
  }
}
@delasy delasy added enhancement New feature or request design This issue or pull request is related to design change labels Apr 21, 2023
@delasy delasy self-assigned this Apr 21, 2023
@delasy
Copy link
Member Author

delasy commented May 24, 2023

We can declare "finally" as a cleanup block that always should be visited AFTER try-catch block. The solution could be:

file_t file = file_open();
{
  switch (setjmp(jmp_buf)) {
    case 0: {
      // try body
      goto L1;
      break;
    }
    case TYPE_error_Error: { // catch err: error_Error
      // catch body
      goto L1;
      break;
    }
    default: { // Unhandled Error
      goto L1;
      break;
    }
  }
L1:
  file_close(file);
}

@delasy
Copy link
Member Author

delasy commented May 24, 2023

Not sure if we need this feature though, if this issue gets enough upvotes I will start on implementing it

@delasy delasy changed the title finally in error handling error handling - finally block Aug 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design This issue or pull request is related to design change enhancement New feature or request
Development

No branches or pull requests

1 participant