Re: Try/Exception handling

From: [at]} <Werner>
Date: Thu, 06 Sep 2001 13:47:20 +0200

> In C++/Java you can "try" some code, knowing that it might fail for various
> reasons, and then recover (via Exception handling) if something does go
> wrong while executing the code.
>
> Has anyone figured out any way to do this with BB?
>
> I'm using BB1.3 to develop a commercial "recording application" that must
> never fail (even if something goes wrong) while it is running. However, it
> interacts with some other windows programs via COM that WILL fail (quite
> often). My program needs to gracefully handle these situations and keep
> going.
>
> I've found that if you need to have some code always called (even if it
> fails sometimes) that you can create a Service.Action that will 1) register
> to be called again 2) calls the code you want to call via Meta or
> Dialog.Call (Haven't really figured out how to use Meta effectively, which
> is sad because it seems so powerful). In the event that the code fails, it
> a) creates a trap window, then b) since the Service.Action has already
> registered itself to be called again, it still gets called despite the trap.
>
> I'm not that wild about this implementation of mine... I don't like having
> the Trap windows always popping up (I wish I could have my own trap handler
> that didn't pop up the window), and also I wish I had a more robust
> Try/Exception handling under BB.
>
> Any thoughts or experiences from anyone?

Yes, we have a similar situation for our WebServer Framework. The
WebServer shall keep running even if errors occur.

First the possbile solutions for BB 1.3 and then below a
nice solution for BB 1.4

BB 1.3
For an action you can do this.

PROCEDURE (a : Action) Do
  BEGIN
    Services.DoLater(a,Services.now);
    MyStuff;
  END;

You don't need to use Meta or Dialog.Call, you can use ordinary
calls also. If you register the Action before you call your code
it will be called again, not depending on the TRAPing or not of
the called code.

So Trap-Windows are nasty sure. One simple solution:


PROCEDURE (a : Action) Do
  BEGIN
    IF a.trap THEN
      GetFocus Window, Close it, Print it or anything else
    END;
    a.trap := TRUE;
    Services.DoLater(a,Services.now);
    MyStuff;
    a.trap := FALSE;
  END;

With this solution you can decide on every run wether the invocation
of the other code led to a trap. Since the Trap-Window ist the
frontmost window you can easily catch it and close it.
If there are several differnt windows you can use the window list
in Module Windows.

----------------
Solution for BB 1.4.
There is a special Module StdDebug2 which enables you to install
an TrapTextHandler to directly catch the trap and then restart
your procedure or react in any other way.
On request OuS made this one for us, but a can ask them for
permission to hand it over to you also.
But it is only available on BB 1.4
-- 
mit freundlichen Grüssen
Werner Braun
O³ Software GmbH & Co. KG * Eichkamp 1 * D-24217 Schönberg
http://www.o3-software.de * Fon: 04344 414171 * Fax: 04344 5385
--------------------------------------------
To unsubscribe from this mailing list, send a message containing the word "unsubscribe" to:
   blackbox-request{([at]})nowhere.xyTo get a list of valid e-mail commands and instructions on their usage, send a message containing the word "help" to the above address.
Send any problem reports or questions related to this email list to the list owner at
   owner-blackbox{([at]})nowhere.xy
Received on Thu Sep 06 2001 - 11:47:20 UTC

This archive was generated by hypermail 2.3.0 : Thu Sep 26 2013 - 06:27:43 UTC