xsharp.eu • XSharp TRY without CATCH
Page 1 of 1

XSharp TRY without CATCH

Posted: Mon Aug 03, 2020 6:32 am
by leon-ts
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

Posted: Mon Aug 03, 2020 6:42 am
by Chris
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.

XSharp TRY without CATCH

Posted: Mon Aug 03, 2020 6:54 am
by leon-ts
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

XSharp TRY without CATCH

Posted: Mon Aug 03, 2020 7:00 am
by SHirsch
Hi Chris,

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
I am aware of the missing catch block. And it would be empty.

Stefan

XSharp TRY without CATCH

Posted: Mon Aug 03, 2020 7:26 am
by Chris
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?

XSharp TRY without CATCH

Posted: Mon Aug 03, 2020 7:42 am
by leon-ts
Chris,

The option will add flexibility and suit both approaches.

Best regards,
Leonid

XSharp TRY without CATCH

Posted: Mon Aug 03, 2020 8:04 am
by SHirsch
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?
You're right. Setting per app/lib is better than globally.

XSharp TRY without CATCH

Posted: Mon Aug 03, 2020 11:52 am
by robert
Guys,

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.
You can enable/disable this warning the usual way, so on the command line but also using compiler pragmas.

Robert

XSharp TRY without CATCH

Posted: Mon Aug 03, 2020 12:00 pm
by leon-ts
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