XSharp TRY without CATCH

This forum is meant for questions and discussions about the X# language and tools
Post Reply
leon-ts
Posts: 435
Joined: Fri Feb 03, 2017 1:43 pm

XSharp TRY without CATCH

Post 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
Best regards,
Leonid
User avatar
Chris
Posts: 4906
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

XSharp TRY without CATCH

Post 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.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
leon-ts
Posts: 435
Joined: Fri Feb 03, 2017 1:43 pm

XSharp TRY without CATCH

Post 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
Best regards,
Leonid
User avatar
SHirsch
Posts: 286
Joined: Tue Jan 30, 2018 8:23 am
Location: Germany

XSharp TRY without CATCH

Post 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
User avatar
Chris
Posts: 4906
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

XSharp TRY without CATCH

Post 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?
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
leon-ts
Posts: 435
Joined: Fri Feb 03, 2017 1:43 pm

XSharp TRY without CATCH

Post by leon-ts »

Chris,

The option will add flexibility and suit both approaches.

Best regards,
Leonid
Best regards,
Leonid
User avatar
SHirsch
Posts: 286
Joined: Tue Jan 30, 2018 8:23 am
Location: Germany

XSharp TRY without CATCH

Post 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.
User avatar
robert
Posts: 4520
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

XSharp TRY without CATCH

Post 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 Development Team
The Netherlands
robert@xsharp.eu
leon-ts
Posts: 435
Joined: Fri Feb 03, 2017 1:43 pm

XSharp TRY without CATCH

Post 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
Best regards,
Leonid
Post Reply