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

Errors from fromJson with non-default-initializable types can't be caught #26874

Open
e-kayrakli opened this issue Mar 7, 2025 · 1 comment

Comments

@e-kayrakli
Copy link
Contributor

e-kayrakli commented Mar 7, 2025

Consider:

use JSON;

config const useClass = true;

class C {
  var x: int;
}

record R {
  var x: int;
}

try {
  if useClass {
    // BUG: The error from the following can _not_ be caught:
    var x = fromJson("{\"y\": 10}", owned C);
    writeln(x);
  }
  else {
    // The error from the following can be caught after #26656:
    var x = fromJson("{\"y\": 10}", R);
    writeln(x);
  }
}
catch {
  writeln("fromJson threw an error");
}

After #26656, we can catch errors when fromJson is used with a default-initializable type. But what #26656 does is just an attempt to paper over the issue. When you use non-default-initializable types, you still can not catch the error thrown by the internal implementation.

This issue has been there since those functions are created and has nothing to do with the way they are implemented, but more about the IO routines they use.

@e-kayrakli
Copy link
Contributor Author

Note also that #26656 is adding a warning for this behavior. When this issue is resolved, that warning needs to be removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants