Hello
Actually I try to catch an error message, show the error to the user and continue. This is not possible if the exception is throw by the server.
Elsewhere in my server code I put the following sequence.
ApplicationException apEx = new ApplicationException("TEST");
TerminateException terminate = new TerminateException(apEx,"Demo");
terminate.ErrorCode = "LedgerInfo.01";
terminate.Context = "Database Request";
throw terminate;
The ApplicationException is a representant of any other exception which is actually thrown. My idea is to catch this exception, put it - together with some other more specific information in a "outer Exception" and throw this again. Then and the end of my routine I will specially catch only the TerminateException, put this into a new TVerificationResultCollection and send this back as an answer. Then you get the following Message.
The problem is: If you do this a second time, it will not work again. You will get the a "very long" error message.
One reason is:
TDBTransaction transaction = DBAccess.GDBAccessObj.BeginTransaction();
ApplicationException apEx = new ApplicationException("TEST");
TerminateException terminate = new TerminateException(apEx,"Demo");
terminate.ErrorCode = "LedgerInfo.01";
terminate.Context = "Database Request";
throw terminate;
ledgerNumber = ALedgerNumber;
ledger = ALedgerAccess.LoadByPrimaryKey(ALedgerNumber, transaction);
DBAccess.GDBAccessObj.CommitTransaction();
If the exception is thrown between a BeginTransaction and a CommitTransaction and you do not commit, you have lost the game.
Only the following sequence helps.
DBAccess.GDBAccessObj.CommitTransaction();
TDBTransaction transaction = DBAccess.GDBAccessObj.BeginTransaction();
ApplicationException apEx = new ApplicationException("TEST");
TerminateException terminate = new TerminateException(apEx,"Demo");
terminate.ErrorCode = "LedgerInfo.01";
terminate.Context = "Database Request";
throw terminate;
ledgerNumber = ALedgerNumber;
ledger = ALedgerAccess.LoadByPrimaryKey(ALedgerNumber, transaction);
DBAccess.GDBAccessObj.CommitTransaction();
So: Run a "DBAccess.GDBAccessObj.CommitTransaction();" as one of the first lines in your code.
Best regards
Wolfgang