Jitex icon indicating copy to clipboard operation
Jitex copied to clipboard

Handling exception on intercept method

Open Hitmasu opened this issue 2 years ago • 0 comments

https://github.com/Hitmasu/Jitex/issues/85#issuecomment-1649120739

When Jitex intercepts a method, we don't add any exception handling. Therefore, if the method throws an exception, the Interceptor will be interrupted without a return or calling ReleaseTask.

Eg.:

public int IsEven(int number) {
  //Jitex interceptor implementation...
  if (context.ProceedCall) {
    if (number == 0)
      throw new InvalidOperationException();

    result = number % 0 == 1;
  }
  callManager.ReleaseTask();
}

Should be:

public int IsEven(int number) {
  //Jitex interceptor implementation...
  if (context.ProceedCall) {
    try {
      if (number == 0)
        throw new InvalidOperationException();

      result = number % 0 == 1;
    } catch (Exception ex) {
      context.SetException(ex);
    }
  }

  if (context.Exception != null)
    throw context.Exception;

  callManager.ReleaseTask();
}

Hitmasu avatar Jul 25 '23 13:07 Hitmasu