Suggestions for conversion VO programs using VO GUI classes

Public support forum for peer to peer support with related to the Visual Objects and Vulcan.NET products
User avatar
ppiko
Posts: 3
Joined: Sat Oct 03, 2015 3:42 am

Suggestions for conversion VO programs using VO GUI classes

Post by ppiko »

Hi guys,

I'll come out of lurker mode ;)

Years ago when I did conference sessions on exception handling I suggested looking at this for ideas: C# Exception Handler. Of course it is not just for C#, and can be applied to any .NET language.

And don't forget to do something about any exceptions that aren't explicitly handled. Put these into your startup code as required:
  • AppDomain.UnhandledException= Notification of uncaught exceptions
  • Application.ThreadException= Triggered by exceptions that occur in Windows Forms threads; by default doesn’t trigger UnhandledException
  • Application.DispatcherUnhandledException= Triggered by exceptions occurring in WPF UI
E.g.

In XAML
<Application x:Class="ExceptionExampleWPF.App"
xmlns="http://schemas.microsoft.com/winfx/2006 ... esentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
DispatcherUnhandledException="MyDispatcherUnhandledExceptionLogger"
StartupUri="Window1.xaml">
</Application>

In code
PROTECTED METHOD OnStartup(e AS StartupEventArgs) AS VOID
// Vulcan
Application.Current:DispatcherUnhandledException += ;
DispatcherUnhandledExceptionEventHandler{SELF,;
@MyDispatcherUnhandledExceptionLogger()}
SUPER:OnStartUp(e)
RETURN

Regards,
Paul
User avatar
wriedmann
Posts: 3757
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Suggestions for conversion VO programs using VO GUI classes

Post by wriedmann »

Hi Chris,

thank you very much!

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
wriedmann
Posts: 3757
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Suggestions for conversion VO programs using VO GUI classes

Post by wriedmann »

Hi Paul,

your contribution is very welcome! It's a long time I have read something from you, and I'm really happy that you are here.
The Exception handler link is very interesting, thank you!

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
NickFriend
Posts: 248
Joined: Fri Oct 14, 2016 7:09 am

Suggestions for conversion VO programs using VO GUI classes

Post by NickFriend »

Hi Chris,

We use something like this for error logging in conjunction with Log4Net. I'd recommend this to everyone... very simple to implement and use and very flexible.

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

Suggestions for conversion VO programs using VO GUI classes

Post by Chris »

That's very nice hearing from you Paul!
It's been a while, hope you're doing well and thanks for contributing!

Chris
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
Chris
Posts: 4922
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Suggestions for conversion VO programs using VO GUI classes

Post by Chris »

Hi Nick,

Thanks for the pointer about Log4Net! But what did you mean you use in conjunction with it? I think you meant Paul's code?

Chris
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
NickFriend
Posts: 248
Joined: Fri Oct 14, 2016 7:09 am

Suggestions for conversion VO programs using VO GUI classes

Post by NickFriend »

Hi Chris,

In our base classes we have some common error logging code which receives the Exception object from the Catch, and does the loop through the InnerExceptions as you showed, then the output can get logged via Log4Net.

Very simple and gives good clear log info for clearing up errors detected at runtime (never happens of course), or just for general logging to see what the program is doing.

Nick
User avatar
Otto
Posts: 174
Joined: Wed Sep 30, 2015 6:22 pm

Suggestions for conversion VO programs using VO GUI classes

Post by Otto »

Arne Ortlinghaus wrote:Hi Otto,
can you give some more information about what you are using?
Arne
Hi Arne,
yes I can.

I use PostSharp, which implements Aspect Oriented Programming.
Your methods focus on the key businesslogic, and all default other kind BS is seperated and backed into Aspects.
If all of your methods must have some kind of exception handling, you define it in one place, and point the methods you want to augment with that behaviour.

In the following example an exception is thrown in the method MyBuggyMethod, caught in the aspect MyOnExceptionAspect, written to the console and ignored (by changing the FlowBehavior to FlowBehavior.Return). You can add logic to log the error, decide whether this exception can be ignored etc, and continue.

Aspects can be used for logging, checking parameters of methods etc.
You can mix XSharp and CSharp in creating Aspects or using them without problem.

I post here the essential pieces of the code:

Code: Select all

BEGIN NAMESPACE Aspects

    /// <summary>
    /// The MyOnExceptionAspect class.
    /// </summary>
    [PSerializable];
    public class MyOnExceptionAspect INHERIT OnExceptionAspect
    
        override public METHOD OnException(args AS MethodExecutionArgs) AS VOID STRICT
        
            Console.WriteLine(i"From within the XSharp OnExceptionAspect: {args.Exception.Message}")
            args:FlowBehavior := FlowBehavior.Return
            return
    END CLASS
END NAMESPACE

Code: Select all

BEGIN NAMESPACE PostSharpTest
    public CLASS Test

            [MyOnExceptionAspect];
            METHOD MyBuggyMethod(mustThrow as LOGIC) as void strict
                IF mustThrow
                    throw Exception{"I had to throw an exception"}
                ENDIF
            RETURN

    END CLASS	
END NAMESPACE // PostSharpTest

Code: Select all

    FUNCTION Start() AS VOID
        Console.WriteLine("Hello World!")
        LOCAL t AS Test
        t := Test{}
        Console.WriteLine("before the buggy method")
        t:MyBuggyMethod(true)
        Console.WriteLine("after the buggy method")

        Console.WriteLine("Press any key to continue...")

        Console.ReadKey()
    RETURN
The output in the console is:

Code: Select all

before the buggy method
From within the XSharp OnExceptionAspect: I had to throw an exception
after the buggy method
User avatar
Meinhard
Posts: 81
Joined: Thu Oct 01, 2015 4:51 pm

Suggestions for conversion VO programs using VO GUI classes

Post by Meinhard »

Hi guys!

Just my two cents...

You should definitely look into the exception handling block of Microsofts Enterprise Library!

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

Suggestions for conversion VO programs using VO GUI classes

Post by ArneOrtlinghaus »

Dieter Crispien 2 years ago proposed also installing a global error handler via AppDomain for all unhandled exceptions similar to the code below saying that this is only for exceptions that cannot be handled ordinarily by a correct error block.
I tested it with a simulated simple runtime error within the GUI classes. The message was output on the screen, but then the app crashed nevertheless.

In Start function after creating shellobject
AppDomain.CurrentDomain:UnhandledException += UnhandledExceptionEventHandler{ oWinShell , @WinShell.UnhandledException()}

PARTIAL CLASS WinShell

METHOD UnhandledException(sender AS OBJECT, e AS UnhandledExceptionEventArgs) AS VOID
LOCAL ex AS Exception

ex := (Exception)e:ExceptionObject

msgerror ("Unhandled exception in program " + errorobject2string(ex))
RETURN

END CLASS
Post Reply