Click here to Skip to main content
15,887,683 members
Home / Discussions / C#
   

C#

 
QuestionVisual Studio 2005 method error Pin
Jem_Jumper18-Jun-09 23:29
Jem_Jumper18-Jun-09 23:29 
AnswerRe: Visual Studio 2005 method error Pin
dan!sh 18-Jun-09 23:35
professional dan!sh 18-Jun-09 23:35 
QuestionHow to run .NET application in Fedora 6(Linux) Pin
Member 305788718-Jun-09 23:12
Member 305788718-Jun-09 23:12 
AnswerRe: How to run .NET application in Fedora 6(Linux) Pin
Rob Philpott18-Jun-09 23:14
Rob Philpott18-Jun-09 23:14 
AnswerRe: How to run .NET application in Fedora 6(Linux) Pin
Simon P Stevens18-Jun-09 23:15
Simon P Stevens18-Jun-09 23:15 
QuestionSoftware Process Change Best Practices Pin
DeveloperZero18-Jun-09 22:49
DeveloperZero18-Jun-09 22:49 
AnswerRe: Software Process Change Best Practices Pin
Eddy Vluggen18-Jun-09 22:56
professionalEddy Vluggen18-Jun-09 22:56 
QuestionNested try/catch blocks Pin
Helfdane18-Jun-09 22:35
Helfdane18-Jun-09 22:35 
I'm somewhat hesitating about using nested try/catch blocks.

The situation which makes me think about is the following situation. Some sample code to illustrate:

SqlConnection conn = new SqlConnection(connectionString);
conn.Open();
SqlTransaction trans = conn.BeginTransaction();

try
{
string query = "query goes here";
SqlCommand command = new SqlCommand(query, conn, trans);
// add parameters
command.ExecuteNonQuery();
trans.Commit();
}
catch 
{ 
trans.Rollback();
}
finally
{
if(conn != null)
{
conn.Close();
conn.Dispose();
}
}

This block has 1 try/catch block but the problem resides in the "conn.Open();" line. When there is a network error the conn.Open() will throw an exception. Putting the conn.Open() in the try/catch block will invalidate the code which now resides in the catch/finally clauses.

So I can use 2 sequential try/catch blocks or a nexted construction. What do you people think?

The consumer isn't a moron; she is your wife.

AnswerRe: Nested try/catch blocks Pin
Christian Graus18-Jun-09 22:41
protectorChristian Graus18-Jun-09 22:41 
GeneralRe: Nested try/catch blocks Pin
Helfdane18-Jun-09 22:45
Helfdane18-Jun-09 22:45 
JokeRe: Nested try/catch blocks Pin
DaveyM6918-Jun-09 22:49
professionalDaveyM6918-Jun-09 22:49 
GeneralRe: Nested try/catch blocks Pin
Helfdane18-Jun-09 22:53
Helfdane18-Jun-09 22:53 
GeneralOT Pin
Vikram A Punathambekar18-Jun-09 23:59
Vikram A Punathambekar18-Jun-09 23:59 
AnswerRe: Nested try/catch blocks Pin
Nagy Vilmos18-Jun-09 22:58
professionalNagy Vilmos18-Jun-09 22:58 
GeneralRe: Nested try/catch blocks Pin
Helfdane18-Jun-09 23:16
Helfdane18-Jun-09 23:16 
GeneralRe: Nested try/catch blocks Pin
Nagy Vilmos19-Jun-09 0:58
professionalNagy Vilmos19-Jun-09 0:58 
GeneralRe: Nested try/catch blocks Pin
PandemoniumPasha18-Jun-09 23:29
PandemoniumPasha18-Jun-09 23:29 
GeneralRe: Nested try/catch blocks Pin
Nagy Vilmos19-Jun-09 0:55
professionalNagy Vilmos19-Jun-09 0:55 
AnswerRe: Nested try/catch blocks Pin
PIEBALDconsult19-Jun-09 5:30
mvePIEBALDconsult19-Jun-09 5:30 
Questionto display image from listview Pin
deleepkv18-Jun-09 22:15
deleepkv18-Jun-09 22:15 
AnswerRe: to display image from listview Pin
Christian Graus18-Jun-09 22:43
protectorChristian Graus18-Jun-09 22:43 
GeneralRe: to display image from listview Pin
deleepkv18-Jun-09 23:57
deleepkv18-Jun-09 23:57 
Questionhow to Include Graph in C# windows Application Pin
Mads11518-Jun-09 20:49
Mads11518-Jun-09 20:49 
AnswerRe: how to Include Graph in C# windows Application Pin
stancrm18-Jun-09 21:03
stancrm18-Jun-09 21:03 
GeneralRe: how to Include Graph in C# windows Application Pin
Mads11518-Jun-09 21:31
Mads11518-Jun-09 21:31 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.