Click here to Skip to main content
       

C#

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page  Show 
AnswerRe: Go to finally in try blockmemberjibesh30 Jan '13 - 7:35 
if you exit the try block it would automatically pass through finally block no matter how it exits the try block i.e either through catch or through return statement.
 
have you tried to debug this. you may paste the code block if it still didnt work.
Jibesh V P

GeneralRe: Go to finally in try blockmembervanikanc30 Jan '13 - 7:37 
I am going to use a return. But this exits the whole program. So, within this condition, I am going to close the connection and have a return.
GeneralRe: Go to finally in try blockmemberjibesh30 Jan '13 - 7:41 
what makes the program to exit? is that how it has to work?
Quote:
So, within this condition, I am going to close the connection and have a return
since you want to close the connection before the application exists thats the best place to do this reset.
Jibesh V P

GeneralRe: Go to finally in try blockmembervanikanc30 Jan '13 - 7:42 
If the database returns 0 rows, exit else continue.
GeneralRe: Go to finally in try blockmemberjibesh30 Jan '13 - 7:44 
Ok. did I answer your question? if not can you please share the code for the better understanding of your problem.
Jibesh V P

GeneralRe: Go to finally in try blockmemberdevvvy31 Jan '13 - 15:44 
Yes, I think the general concensus is that, put try-catch-finally in all thread functions as coding practice.
dev

AnswerRe: Go to finally in try blockmvpEddy Vluggen30 Jan '13 - 7:45 
vanikanc wrote:
If I use Environment.Exit(); then it will end the program, and I would not have closed the connection to database that is open.

It will not end the program, but terminate it.
 
Use Application.Terminate for a WinApp, and simply return from the Main method (the entry-point) if you're writing a Console App.
Bastard Programmer from Hell Suspicious | :suss:
If you can't read my code, try converting it here[^]
They hate us for our freedom![^]

AnswerRe: Go to finally in try blockmemberPIEBALDconsult30 Jan '13 - 7:53 
vanikanc wrote:
two try blocks, two catches and one finally block

 
You'd have to show the code for us to understand how you have them arranged.
 

vanikanc wrote:
closed the connection to database

 
You should be using a using statement as well -- it's similar to a try/finally.
 

vanikanc wrote:
Environment.Exit();

 
Don't do that; just return.
AnswerRe: Go to finally in try blockmemberjschell30 Jan '13 - 8:04 
vanikanc wrote:
then it will end the program, and I would not have closed the connection to
database that is open.

 
When the program terminates the connection will be terminated as well.
 
And the only way you can terminate a database connection in C# anyways is if all of the following are true.
1. You have configured the connection pool to keep no idle connections.
2. There are no connections in use
3. You reset the pool.
 
Other than that just "closing" the connection does nothing more than return it to the connection pool.
AnswerRe: Go to finally in try blockmvpAbhinav S30 Jan '13 - 21:32 
Just return from the method. The finally block will execute and then your method will return.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   


Advertise | Privacy | Mobile
Web02 | 2.6.130523.1 | Last Updated 23 May 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid