Barry Kelly
Re: Exceptions vs Error codes

Re: Exceptions vs Error codes

"Barry Kelly" <‚úČ> wrote in message >
> Please list some valid uses of exception-swallowing try..except blocks,
> and I'll show you that the majority should have checked for error before
> doing whatever raised the exception.

Of course, but that doesn't mean we can't use them to our advantage. Here is
a common one that I use all the time. (And I mean, ALL THE TIME).

While I am working on creating a new procedure for Interbase, initially, the procedure doesn't exist. However, as I'm working on debugging the code and it's functionality, I frequently have to replace it with the new version. So, in my code that creates the procedure, I put this:
    MyQuery.SQL.Text := 'Drop procedure WhatEver';     try         MyQuery.ExecSQL;     except     end;     MyQuery.SQL.Text := 'Procedure WhatEver (SomeParam Int)';     MyQuery.SQL.Add('more code here');     .     This let's me not worry about dropping the procedure the first time (because I KNOW it doesn't even exist yet) and also runs flawlessly at the client's if they happen to hit the update button more than once. I know that I could put in code to check the existence of the procedure first, or even create a procedure to do it for me by passing the name, but it's quicker this way for me.
FYI: Phrase searches are enclosed in either single or double quotes
Originally created by
Tamarack Associates
Tue, 07 Feb 2023 05:39:49 UTC
Copyright © 2009-2023
HREF Tools Corp.