thiru.A

Hi ,

Could u just confirm me ,the following way of using try catch block is valid one I mean the nested one.

try

{

//Insert the signature Value.

sqlQuery = "Insert into signature values (@sign);select max(signatureid) from signature";

command = new SqlCommand(sqlQuery, connection);

command.Transaction = transaction;

command.Parameters.AddWithValue("@sign", mailCollection.mailDetail[0].signature);

signId = Convert.ToInt32(command.ExecuteScalar());

returnString = "Success";

}

catch (Exception ex)

{

try

{

transaction.Rollback();

}

catch (InvalidOperationException exp)

{

General.WriteLog(exp.Message.ToString());

}

DiposeObject();

General.WriteLog(ex.Message.ToString());

returnString = "Error Occurred";

}

Also confrim me ,using of try catch block affect the performance in anyway.

If it is so,pls., let me know how to handle try catch block in effective manner.Thanks.



Re: Visual C# General Reg:try catch Block

Be.St.

I think it's formally correct.

Maybe you can consider using Microsoft Enterprise Library for better performance and error handling.

About performance I read that a try-catch block require 20 CPU cycles, so if u call it in a loop u might have a performance loss.

Stefano Benedetti






Re: Visual C# General Reg:try catch Block

Manju Sandhu

Hi,

Yes the way you have nested try catch block is fine.

Try catch block decrease speed.

So my suggestion is that don't use try catch when you are using it only for logging and rethrowing the exception.

Regards,

Manju Sandhu





Re: Visual C# General Reg:try catch Block

RizwanSharp

Nested try/catch block are ok unless they create recursion which will lead your application to break after a number of recursions....

So You situaion is quite ok and Normal which is not creating any type of recursion.

Best Regards,

Rizwan aka RizwanSharp






Re: Visual C# General Reg:try catch Block

thiru.A

Thanks Stefano ,Could u just let me know how to go abt using Microsoft Enterprise Library for better performance and error handling.I too heard abt the same but no idea abt how to use it.





Re: Visual C# General Reg:try catch Block

Be.St.

Hi, I suggest you visiting the Enterprise Library Home at msdn.microsoft.com/entlib/

If u use .Net Framework 2.0 or above you can download the EntLib 3.0 or 3.1

And u can follow the getting started section:

  1. Download Enterprise Library.
  2. Install Enterprise Library and compile all application blocks and tools.
  3. Read the "Introduction" and "Scenarios and Goals" sections of the documentation.
  4. Compile and run the QuickStart samples, and read through the related "QuickStart Walkthroughs" and "Key Scenarios" sections of the documentation.
  5. If the application block looks like a good fit for your application, try implementing a simple use case in your application or in a throw-away prototype application using the application block.

For your needs you can start using the data access block. After installing you have a program group folder in your start menu called Microsoft Patterns and Practices. For each block there are lots of samples.

Let me know.

Stefano Benedetti






Re: Visual C# General Reg:try catch Block

thiru.A

Though i cant understand what u have said in my very first look ,let me try to understand it.Thanks.





Re: Visual C# General Reg:try catch Block

thiru.A

Dear Stefano,

All these time,I learnt abt MS Enterprise Library features & its purpose and quite interested in availing its services.

Im trying to implement MS Enterprise Library in my Smart Devices application.

Though we are speaking abt patterns & pratices still wanna confirm from u whether MS Enterprise Library supports Smart Devices Application.

If it extends it supports how to go abt configuration settings as ce application dont have config file by default and also let me know the procedure how to add the downloaded enterprise library to my application.

Right now i have installed enterprise library in c:\programfiles.





Re: Visual C# General Reg:try catch Block

Be.St.

I didn't know u was speaking about smart devices in which I'm not specialized.

Maybe this link can help u:

http://msdn2.microsoft.com/en-us/library/aa480471.aspx






Re: Visual C# General Reg:try catch Block

thiru.A

Hi Stefano .

I browsed through the path,where i have installed the downloaded Microsoft Enterprise Library 3.1¡ªMay 2007 edition,

C:\Program Files\Microsoft Enterprise Library 3.1¡ªMay 2007\Bin folder and trying to add these two following required assembly as a references to my web project:

  • Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.dll
  • Microsoft.Practices.EnterpriseLibrary.Common.dll

Surprizing ,I cant find those, could u just let me know the mistake I did.

regards,

thiru.





Re: Visual C# General Reg:try catch Block

Be.St.

First time you have to build them from the start menu.

Under Microsoft Practices - Enterprise Library

you find Build enterprise library and then Copy assembly to bin folder.

Hi