Inconsistent Error and Exception Handling: Difference between revisions

From OpenPetra Wiki
Jump to navigation Jump to search
(Moved some input from ThiasG to page 'Error and Exception Handling Policy'.)
(Moved input from WolfgangU to new page 'A Use Case for a Custom Exception'.)
Line 19: Line 19:


--[[User:Thiasg|Thiasg]] 09:27, 31 January 2011 (UTC)
--[[User:Thiasg|Thiasg]] 09:27, 31 January 2011 (UTC)
== Nested Exceptions (Wolfgang U) ==
Let me point out another important part of the error handling policy and this are nested and parametrizde exceptions.
Let us see the following code:
    public class InvalidLedgerInfoException: SystemException
    {
    public InvalidLedgerInfoException(string message, Exception innerException)
    : base(message, innerException) {}
    }
   
    public class GetLedgerInfo
    {
    int ledgerNumber;
    private ALedgerTable ledger=null;
   
    public GetLedgerInfo(int ALedgerNumber)
    {
    ledgerNumber = ALedgerNumber;
    ledger = ALedgerAccess.LoadByPrimaryKey(ALedgerNumber, null);
    }
   
    public string RevaluationAccount
    {
   
    get {
    try {
    ALedgerRow row = (ALedgerRow)ledger[0];
    return row.ForexGainsLossesAccount;
    } catch (Exception caughtException)
    {
    string message =
    "The RevaluationAccount of leger {0} has been unsuccessfully required!";
    throw new InvalidLedgerInfoException(
    String.Format(message, ledgerNumber) ,caughtException);
    }
    }
    }
   
    }
A data table is read and only the content of a field is used. If we use the test code line
  Assert.AreEqual("5003", new GetLedgerInfo(44).RevaluationAccount, "...");
we get the following result.
[[File:NestedExceptions.JPG]]
This means that we have the info:
: Tests.MFinance.GL.TRevaluationTests.T03_GetLedgerInfo:
:Ict.Petra.Server.MFinance.GL.InvalidLedgerInfoException : The RevaluationAccount of leger 44 has been unsuccessfully required!
:  ----> System.IndexOutOfRangeException : There is no row at position 0.
In normal cases we only have the information of the System.IndexOutOfRangeException in specific file and line but now we have the additional information that the ledger number 44 has been requested. Even if programm is delivered without any debug info, we now new a user level reason for the error (wrong ledger number) and the programm level consequences for the software (There is no row at position 0).
An interesting article about this problem(s) you can find here: [http://blog.gurock.com/articles/creating-custom-exceptions-in-dotnet/ Creating Custom Exceptions in .NET]

Revision as of 11:03, 3 May 2011

Overview

We do not yet have a consistent way of handling errors in all situations. This is strongly desired.

TODO: Extend the Error and Exception Handling Policy - especially in the areas of Client and Server error handling.


Input from ThiasG

Expected System-Exceptions shall be caught and be put into an OpenPetra-specific Exception. This help to differentiate between programmed errors and expected Exception conditions.


Until now, we have not added anything about handling the exception, e.g. handling the exception in the client, aborting the current function, logging the exception and showing the error to the user.


We need to add something about handling extreme cases, such as

  • Losing connection to DB;
  • Client-Server/Server-Client connection;
  • other cases?

What to do in such situations: Do we stop the client session? In which cases the server needs to stop? - Not all error conditions are initiated by a function call from the client.

--Thiasg 09:27, 31 January 2011 (UTC)