Click here to Skip to main content
14,866,384 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hi,
In my application when exception occurs i need to pass the Error Code from the Business Layer
to the Presentation layer here based on the error code i need to show the message that is available in the DB.
I want to know how to pass and get the Error code in the Presentation Layer.
For logging Exceptions i am using log4net and Enterprise library 4.0.

Thanks in advance
Posted
Updated 25-Apr-13 20:15pm
v2
Comments
Prasad Khandekar 26-Apr-13 2:12am
   
Some code please? How are you passing error code into presentation layer?
ravithejag 26-Apr-13 2:20am
   
@prasad i may be using log4net for passing error codes
Prasad Khandekar 26-Apr-13 2:50am
   
log4net will be used for logging. That's ok. May be this (http://www.mindfiresolutions.com/How-to-create-Ordered-List-in-ASPNET-1020.php) article will help you. It's not about displaying errors but shows how you can display multiple values in an ordered list.
ravithejag 26-Apr-13 2:59am
   
hi if Exception occurs i need to throw the error code(present in DB) from Business layer to presentation layer
ravithejag 26-Apr-13 3:01am
   
we will pass the error code manually from our side

1 solution

Use your own Exceptions. Create appropriate exception classes inheriting from System.Exception or System.ApplicationException or other, and add your ErrorCode property. Thrown the exception when appropriate in the Business Layer. In the Presentation Layer, you need some try...catch blocks, and when you catch one of your specific exceptions, you can access its error code and get the wording for it.
Note that you can have multiple catch blocks after a try, the most specific exception has to come first:
C#
try
{
    ...some code
}
catch (MyException mex)
{
    string msg = GetMessage(mex.ErrorCode);
    ...
}
catch (System.Exception ex)
{
    ...
}
   
Comments
ravithejag 26-Apr-13 3:24am
   
thanks Bernhard

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900