Re: Evaluating Exceptions, Try Except and Try Finally
From: Skybuck Flying (nospam_at_hotmail.com)
Date: 04/08/04
- Next message: Rob Kennedy: "Re: Record type flushing"
- Previous message: Skybuck Flying: "Re: Evaluating Exceptions, Try Except and Try Finally"
- In reply to: Skybuck Flying: "Re: Evaluating Exceptions, Try Except and Try Finally"
- Next in thread: Bruce Roberts: "Re: Evaluating Exceptions, Try Except and Try Finally"
- Reply: Bruce Roberts: "Re: Evaluating Exceptions, Try Except and Try Finally"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 8 Apr 2004 19:50:48 +0200
"Skybuck Flying" <nospam@hotmail.com> wrote in message
news:c53vhg$pvq$1@news5.tilbu1.nb.home.nl...
>
> "Rob Kennedy" <me3@privacy.net> wrote in message
> news:c53ssh$2pd76l$1@ID-220940.news.uni-berlin.de...
> > Skybuck Flying wrote:
> > > Try
> > > Try
> > > Connection.Open
> > > Finally
> > > Connection.Close
> > > end;
> > > Except
> > > On Exception
> > > end;
> > >
> > > The only big drawback is that... the exception will happen after the
> > > connection is closed.. that's weird !
> >
> > If there was an exception, then the connection was never opened in the
> > first place
>
> No, that's where you are wrong because after the open statement other
> instructions
> follow which can also procedure exceptions.
>
> That's why the try except block is surrounding the try finally block, so
to
> catch those exceptions.
Though I now realize that this pseudo code would be better.
The documentation in delphi about try/finally was hard to understand for
me... see other posts =D
The documentation read: "finally will always get executed"! That is
ofcourse not true if an exception happens before the try block is entered !
Actually I saw some other programming language I think it was visual
basic...and I thought nicccee:
try
catch
finally
end;
Or something like:
try
{
}
finally
{
}
Delphi just has:
try
nothing <- a bit weird.
finally
end;
Oh well.
I now see how this pseudo code would be better:
try
Connection.Open;
IF AN EXCEPTION OCCURS HERE THE TRY FINALLY BLOCK WILL BE SKIPPED !
SO CLOSE WILL NEVER GET CALLED WHICH IS PROBABLY OK ANYWAY
SINCE THE CONNECTION DID NOT OPEN ???!!!??
UNLESS OFCOURSE IT DID OPEN BUT SOME OTHER KINDS OF WACKY EXCEPTION
OCCURED !!!!
HAHAHAHAHA
THAT ONCE AGAIN PROOFS HOW STUPID EXCEPTIONS ARE !!!!!!!!
WHAT IF A STUPID DIV BY ZERO OCCURED OR SO WHICH IS NON CRITICAL AND THE
CONNECTION
WAS STILL OPENED !!!!
THERE IS JUST NO WAY TO KNOW FOR SURE...
UNCERTAINTY/DOUBTFULL/AMBIGUITY :):):)
UNLESS SOME STUPID DOCUMENTATION SAYS:
"NONONONONONO CONNECTION.OPEN WILL NEVER RAISE AN EXCEPTION IF IT DID
OPEN"
I'll bet a billion bucks the .NET doc doesn't say that !
So in short:
What if Connection.Open did succeed... but some kind of other exception
was raised. I don't care what it was...
The result is: The connection won't be closed ! so we still have a god
damn problem !
HA HA HA HA HA
All this shit could be easily solved with IF STATEMENTS !!!
if Connection.Open then <---- CERTAINTY ! :P
begin
Connection.Close;
end;
There is no way this logic would ever fail ! :P
Rest of stupid exception code:
try
Execute SQL
finally
Connection.Close; // always close connection if it opened. unless
open did work but other stupid exception was raised.
end;
except
// catch connection exception
or
// catch execute sql exception
// catch other exceptions !
end;
.NET documentation:
Opens a database connection with the settings specified by the
ConnectionString property of the provider-specific Connection object.
[Visual Basic]
Sub Open()
[C#]
void Open();
[C++]
void Open();
[JScript]
function Open();
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows
2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003
family, .NET Compact Framework - Windows CE .NET
See Also
IDbConnection Interface | IDbConnection Members | System.Data Namespace |
IDbConnection Members (Visual J# Syntax) | Managed Extensions for C++
Programming
Syntax based on .NET Framework version 1.1.
Documentation version 1.1.0.
----------------------------------------------------------------------------
---- It does even say that it could throw exceptions ! Let alone what other exceptions it could raise ! Skybuck.
- Next message: Rob Kennedy: "Re: Record type flushing"
- Previous message: Skybuck Flying: "Re: Evaluating Exceptions, Try Except and Try Finally"
- In reply to: Skybuck Flying: "Re: Evaluating Exceptions, Try Except and Try Finally"
- Next in thread: Bruce Roberts: "Re: Evaluating Exceptions, Try Except and Try Finally"
- Reply: Bruce Roberts: "Re: Evaluating Exceptions, Try Except and Try Finally"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|