Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET C#4.0 Exception Errors , +
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 25-Apr-13 21:03pm
Edited 25-Apr-13 21:15pm
v2
Comments
Prasad Khandekar at 26-Apr-13 2:12am
   
Some code please? How are you passing error code into presentation layer?
ravithejag at 26-Apr-13 2:20am
   
@prasad i may be using log4net for passing error codes
Prasad Khandekar at 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 at 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 at 26-Apr-13 3:01am
   
we will pass the error code manually from our side

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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:
try
{
    ...some code
}
catch (MyException mex)
{
    string msg = GetMessage(mex.ErrorCode);
    ...
}
catch (System.Exception ex)
{
    ...
}
  Permalink  
Comments
ravithejag at 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)

  Print Answers RSS
0 OriginalGriff 350
1 Jochen Arndt 190
2 Richard MacCutchan 135
3 Sergey Alexandrovich Kryukov 130
4 DamithSL 105
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,310


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 26 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100