Error handling in X# vs VO

This forum is meant for anything you would like to share with other visitors
NickFriend
Posts: 248
Joined: Fri Oct 14, 2016 7:09 am

Error handling in X# vs VO

Post by NickFriend »

Fair enough! Anyway, glad the idea was useful.

Nick
User avatar
ArneOrtlinghaus
Posts: 412
Joined: Tue Nov 10, 2015 7:48 am
Location: Italy

Error handling in X# vs VO

Post by ArneOrtlinghaus »

I think that it is not possible to add something like this, because it is a contradiction to exception handling. Especially when thinking in future multithreaded processes, a global error handler for all threads reacting on one thread without interfering the other should not be possible.

When working with Windows Forms it seems to be that every window event like pressing push buttons, setting/loosing focus etc. seems to be capsulated by windows forms using correct try blocks and calling the application code from there. This way, if an error is not handled correctly, an exception occurs only for that event and not for the whole application.

For the GUI classes we must insert similar behavior to get robust applications, otherwise a single error crashes the application. I have seen that sometimes unhandled errors in the GUI classes in X# cash the program without any error message at all.

Arne
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Error handling in X# vs VO

Post by wriedmann »

Hi Arne,

I was thinking for that only for the VO dialect and when using begin/end sequence.

In newly written code it would be better to use try/end try directly, without any addition.

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
Chris
Posts: 4906
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Error handling in X# vs VO

Post by Chris »

Hi Wolfgang,

That was not forgotten, it's just one of the things that will have to wait for probably 2.1 or 2.2, same with being able to pass arguments by reference to untyped methods, debugging improvements, further VS integration improvements etc. Just not possible to do all we wanted for 2.0, but obviously development does not stop there.

If something like you propose will be implemented (after making enough investigation to make sure it is a viable solution), it will be implemented most probably optionally only, with a compiler option. But still, I suspect it will not help much, because IMO the biggest difference between VO and .Net is that VO provides error handling even without BEGIN SEQUENCE blocks at all, allowing you to continue execution after the error has happened, from the next line! End even if you have SEQUENCE blocks like this:

BEGIN SEQUENCE

CallSomeCodeThatCAusesAnException()

// rest of the code

RECOVER

END SEQUENCE

then if an exception happens inside the call, then program control is not automatically moved to the RECOVER section, but the user (or the programmer) still has the option to keep executing the "rest of the code" section, or even the code inside the function that caused the exception and has no error handling itself at all.

This is indeed a powerful feature of VO, but unfortunately there's nothing in .Net that could be used to emulate this. Unless maybe if the compiler automatically (optionally again) inserted a TRY block for EVERY single line of code, implementing this kind of error handling. Of course this would lead to HUGE exes/dlls, but maybe this is not a very big problem. Probably it would also hurt performance a lot, but then again maybe it will not be too much...it's something to experiment with.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Error handling in X# vs VO

Post by wriedmann »

Hi Chris,

I do know only my code - and I have written much VO code the last 20 years <g>. When moving code to X#, several times I had code that failed in X# and I didn't knew where...
An option to put every single line of code in a try/catch statement would be very welcome for debugging purposes, but for the "normal" migrated code a begin/end sequence replacement as I suggested would help - of course optional with a compiler switch, but this should be set by default by the Xporter.
It is very important that migrations work without the minor issues possible, otherwise people will loose the confidence.
And, as I wrote, I see this different behaviour between VO and X# as one of the most challeging ones.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Fab64
Posts: 63
Joined: Mon Nov 23, 2015 12:26 pm

Error handling in X# vs VO

Post by Fab64 »

Hi Chris, Wolfgang,

All my VO code contains

BEGIN SEQUENCE
.....
RECOVER
......
END SEQUENCE

or

BEGIN SEQUENCE

...........
IF ........
BREAK
END IF

..............

RECOVER
..........
END SEQUENCE

and a way to implement it also in .NET is welcome.

Fabrizio
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Error handling in X# vs VO

Post by wriedmann »

Ciao Fabrizio,
AFAIK the code

Code: Select all

begin sequence
<code>
recover
<code>
end sequence
will be replaced by

Code: Select all

try
<code>
catch
<code>
end try
This is not the real problem.
The real problem is that in VO you can set your own errorblock, and it is called every time an error is occurring.
In .NET this is not the case - you have to catch the errors by yourself in the catch block.
Therefore my suggestion was to replace the VO begin/end sequence by something like this (pseudo-code):

Code: Select all

try
<code>
catch oEx as Exception
ExecuteErrorBlock( oEx )
<code>
end try
or even a sequence without recover block with the same construct.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Fab64
Posts: 63
Joined: Mon Nov 23, 2015 12:26 pm

Error handling in X# vs VO

Post by Fab64 »

HI Wolfgang,
ok, now it's clearer to me.
the real problem is managing the ERRORBLOCK in X # (.NET).

Fabrizio
User avatar
Chris
Posts: 4906
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Error handling in X# vs VO

Post by Chris »

Hi Fabrizio,
Fab64 wrote:HI Wolfgang,
ok, now it's clearer to me.
the real problem is managing the ERRORBLOCK in X # (.NET).
Yeah, apart from ErrorBLock() handling, everything else in this area works the same way in X# as in VO. The pseudo code you posted compiles also in X# with zero changes. What Wolfgang mentioned about BEGIN SEQUENCE code being replaced by TRY...END TRY is what happens under the surface by the compiler, but your own source code does not need to change at all.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
Fab64
Posts: 63
Joined: Mon Nov 23, 2015 12:26 pm

Error handling in X# vs VO

Post by Fab64 »

Hi Chris,
ok.
Fabrizio
Post Reply