Hi,
When adding a TRY block to the code, if you skip the CATCH and FINALLY sections, the XSharp compiler will not generate an error. Moreover, if you examine the compiled code using ILSpy, you can see that the compiler itself has added the missing empty CATCH block. This can lead to subtle errors when the programmer forgot to implement the CATCH block, but the TRY block has a THROW operator. As a result, a possible error caught in THROW goes silently into an invisible CATCH. And as a result, such an invisible error can live undetected for a long time. For example, in C # in such a situation, the compiler generates the error "Expected catch of finally."
Perhaps the XSharp team specifically implemented this behavior? Therefore, I did not describe it in Tickets on GitHub, but brought it here to the forum for discussion. It seems to me that the compiler should react to the situation described above with an error. This is meant only for the TRY block, not for the BEGIN SEQUENCE block (which works in XSharp as in VO, and even better).
Best regards,
Leonid
XSharp TRY without CATCH
XSharp TRY without CATCH
Best regards,
Leonid
Leonid
XSharp TRY without CATCH
Hi Leonid,
That's because of me . Ok and a few others, who have existing vulcan code with such TRY...END TRY commands with no CATCH or FINALLY clauses, since vulcan allowed it. I have literally 1000s of constructs like that, so X# needed to allow that as well.
But I agree, there should be a compiler warning at least for this. I thought there already was one, but I just checked and there isn't, so I will log this to be added in one of the next builds.
That's because of me . Ok and a few others, who have existing vulcan code with such TRY...END TRY commands with no CATCH or FINALLY clauses, since vulcan allowed it. I have literally 1000s of constructs like that, so X# needed to allow that as well.
But I agree, there should be a compiler warning at least for this. I thought there already was one, but I just checked and there isn't, so I will log this to be added in one of the next builds.
Chris Pyrgas
XSharp Development Team
chris(at)xsharp.eu
XSharp Development Team
chris(at)xsharp.eu
XSharp TRY without CATCH
Hi Chris,
If this behavior is implemented intentionally, then the warning will suffice. Something should draw the developer's attention to the missing CATCH block.
Thanks!
Best regards,
Leonid
If this behavior is implemented intentionally, then the warning will suffice. Something should draw the developer's attention to the missing CATCH block.
Thanks!
Best regards,
Leonid
Best regards,
Leonid
Leonid
XSharp TRY without CATCH
Hi Chris,
if there will be a warning implemented - please as a global compiler switch.
I have several code like this
I am aware of the missing catch block. And it would be empty.
Stefan
if there will be a warning implemented - please as a global compiler switch.
I have several code like this
Code: Select all
TRY; ...some code....; END TRY
TRY; ...some code....; END TRY
TRY; ...some code....; END TRY
Stefan
XSharp TRY without CATCH
Agreed with both of you guys, the warning would be like any other warning which can be enabled/disabled through the compiler options in the app/project settings. Not completely globally, but I think it's not a big problem spending in total 10 minutes (if you have dozens of libraries) adding this option to all the project options, is it?
Chris Pyrgas
XSharp Development Team
chris(at)xsharp.eu
XSharp Development Team
chris(at)xsharp.eu
XSharp TRY without CATCH
Chris,
The option will add flexibility and suit both approaches.
Best regards,
Leonid
The option will add flexibility and suit both approaches.
Best regards,
Leonid
Best regards,
Leonid
Leonid
XSharp TRY without CATCH
You're right. Setting per app/lib is better than globally.Not completely globally, but I think it's not a big problem spending in total 10 minutes (if you have dozens of libraries) adding this option to all the project options, is it?
XSharp TRY without CATCH
Guys,
I have added the following warning:
You can enable/disable this warning the usual way, so on the command line but also using compiler pragmas.
Robert
I have added the following warning:
Code: Select all
warning XS9101: Try statement found without CATCH clause and without FINALLY clause. The compiler will generate a default CATCH clause that catches and ignores all exceptions.
Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
The Netherlands
robert@xsharp.eu
XSharp TRY without CATCH
Hi Robert,
It's fine!
P.S. It would be nice to display the first word in the warning message in uppercase: TRY instead of Try. To make it immediately clear that we are talking about a keyword.
Best regards,
Leonid
It's fine!
P.S. It would be nice to display the first word in the warning message in uppercase: TRY instead of Try. To make it immediately clear that we are talking about a keyword.
Best regards,
Leonid
Best regards,
Leonid
Leonid