I thought I was doing this properly over the years but just realized I'm doing it wrong when I was losing an Out of Bounds OS exception.
My general approach when I write code is to encapsulate every routine with a T/E and append the E.messages so that I get a Traceback list of the calling routines that lead to the exception.
I need to do this because I have a lot of little low-level "widget" routines that if they fail, it could be from any part of the code.
NOTE: Yes, I know about the IDE Debugger but for the way this code is run by many machines on a network, using the IDE is not as easy at it would seem.
I have found the following to be true when nested T/E are involved, especially through the tree of routines called:
1) I have to RAISE an error in the Except block, otherwise the Except is executed and the program continues,
2) When I Create my Error to be Raised, the message parameter is appended with the class and E.Message of the exception that occurred. This could be an exception that I Raise in my code or an OS exception.
3) Each T/E then appends information relevant to the location of the T/E, at a minimum, it will be the name of the routine it is in. If I get fancy, it will also include the parameter values and other internal information.
4) Every T/E in the program is done like this except for the Top Level T/E.
5) The Top Level T/E has the ShowMessage with the final concatenated error message.
At least, this is what I think should work at this point. My previous version of this assumed that the OS exception message in E.message was available when the Top Level T/E was reached. What I did not realize was that when I Raised my created error, that message overwrote the OS message. Therefore SOLUTION was to always start with appending the E.message first to my newly created exception. That should preserve the OS exception message.
________________________________
If there is a better way to do this, I'd like to hear about it. BTW, I'm stuck in Delphi 7 land. My partner started to migrate to the newer versions and the IDE was a nightmare. With lots of difficulty involved and then the MS .NET arriving, he decided to jump ship to .NET so that was the end of Delphi here. I've been working on this project since D7 was the current version and simply have stayed with it.
Thanks in advance,
Tom
My general approach when I write code is to encapsulate every routine with a T/E and append the E.messages so that I get a Traceback list of the calling routines that lead to the exception.
I need to do this because I have a lot of little low-level "widget" routines that if they fail, it could be from any part of the code.
NOTE: Yes, I know about the IDE Debugger but for the way this code is run by many machines on a network, using the IDE is not as easy at it would seem.
I have found the following to be true when nested T/E are involved, especially through the tree of routines called:
1) I have to RAISE an error in the Except block, otherwise the Except is executed and the program continues,
2) When I Create my Error to be Raised, the message parameter is appended with the class and E.Message of the exception that occurred. This could be an exception that I Raise in my code or an OS exception.
3) Each T/E then appends information relevant to the location of the T/E, at a minimum, it will be the name of the routine it is in. If I get fancy, it will also include the parameter values and other internal information.
4) Every T/E in the program is done like this except for the Top Level T/E.
5) The Top Level T/E has the ShowMessage with the final concatenated error message.
At least, this is what I think should work at this point. My previous version of this assumed that the OS exception message in E.message was available when the Top Level T/E was reached. What I did not realize was that when I Raised my created error, that message overwrote the OS message. Therefore SOLUTION was to always start with appending the E.message first to my newly created exception. That should preserve the OS exception message.
________________________________
If there is a better way to do this, I'd like to hear about it. BTW, I'm stuck in Delphi 7 land. My partner started to migrate to the newer versions and the IDE was a nightmare. With lots of difficulty involved and then the MS .NET arriving, he decided to jump ship to .NET so that was the end of Delphi here. I've been working on this project since D7 was the current version and simply have stayed with it.
Thanks in advance,
Tom