Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
5
Erster Beitrag:
vor 2 Monaten, 3 Wochen
Letzter Beitrag:
vor 2 Monaten, 3 Wochen
Beteiligte Autoren:
Yogi Yang, Peter Holemans, Steven Sitas

[WX] - What are the best practices for: Error and Exception Management?

Startbeitrag von Yogi Yang am 18.09.2017 05:15

Hello,

I am still not able to decide as to how to handle Exceptions programmatically.

As there are many pros here on these forums I would like to know:
What are the best practices for: Error and Exception Management?

TIA

Antworten:

Hi Yogi Yang,

You could take a look at the published WX OO framework I wrote many years ago...
There is a more recent one that has some reworked error handling I refactored in V20. I'll see if I can extract it from an old project and post it again.

Error handling:
It has an ErrorMessage and ErrorList class that allows you to track error messages in a complete business process flow.

Exception handling:
Most methods and functions also have a WHEN EXCEPTION handler that logs (and emails if activated) encountered exceptions.

Cheers,

Peter

von Peter Holemans - am 18.09.2017 07:13
Thanks Peter.

That would be really nice.

Actually I have been a bit confused as to how the hell I should handle errors without crashing my application.

TIA

von Yogi Yang - am 19.09.2017 05:45
Hi YY,

You can already download the original release from the PCSoft repository site.

Bye,

Peter

von Peter Holemans - am 19.09.2017 06:48
Hi,
here is a simple explanation on how we do it:

1 - We NEVER do any kind of DIRECT (CRUD) Add, Read, Modify or Delete in the UI (Windows or Pages).
2 - All CRUDs are done in procedures, inside a TRANSACTION frame and always return a TRUE/FALSE and (maybe) an error.
3. We check the Automatic management of errors and exceptions for EVERY procedure and add code at the end (see the example).
4. CRUD procedures always come in pairs - one handles the transaction and the other the CRUD functionality.
5. We never use WHEN EXCEPTION IN etc inside the CRUD procedures.

Here are SIMPLE procedures (Business Process) for Deleting a record from a file called Dummy in a C/S HFSQL environment:

/////////////////////////////////////////////////////////////////////////////////
Procedure DeleteDummy (LOCAL p_sPrimaryKey is string, p_sErrorMessage is string)
HOnError("*",hErrAll,"")
p_sErrorMessage=""

IF HTransactionStart(myConnection)=False THEN
p_sErrorMessage="problem Starting the C/S transaction ..."
RESULT False
END

IF DeleteDummy_private(p_sPrimaryKey, p_sErrorMessage)=False
// Cancel the transaction ...
IF HTransactionCancel(myConnection)=False THEN
// very nasty problem - should never happen
// So end the Program and LET the C/S Engine handle it automatically
EndProgram()
END
END

// Validate the transaction
IF HTransactionEnd(myConnection)=False THEN
// very nasty problem - should never happen
// So end the Program and LET the C/S Engine handle it automatically
EndProgram()
END

RESULT True

// take care of exceptions and other errors
CASE ERROR:
p_sErrorMessage="HFSQL error: " + HError()
RESULT False

CASE EXCEPTION:
p_sErrorMessage="Exception:"+ExceptionInfo(errCode)
RESULT False

////////////////////////////////////////////////////////////////////////////////////////////

Procedure DeleteDummy_private (LOCAL p_sPrimaryKey is string, p_sErrorMessage is string)

IF HReadSeekFirst(Dummy,sDummyPK,p_sPrimaryKey =False THEN
p_sErrorMessage="Record not found"
RESULT False
END

HDelete(Dummy)
IF ErrorOccurred THEN
IF HErrorIntegrity() THEN
p_sErrorMessage="Integrity Issue"
RESULT False
ELSE
p_sErrorMessage="HFSQL error: " + HError()
RESULT False
END
END

RESULT True
// take care of exceptions and other errors
CASE ERROR:
p_sErrorMessage="HFSQL error: " + HError()
RESULT False

CASE EXCEPTION:
p_sErrorMessage="Exception:"+ExceptionInfo(errCode)
RESULT False

//////////////////////////////////////////////////////
Steven Sitas
www.alpha360.biz

von Steven Sitas - am 19.09.2017 09:11
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.