473,748 Members | 2,426 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need help with ApplicationExce ption

I need to find a way to share information between two classes, one is an
employee class and the other is a custom error class that inherits from
ApplicationExce ption. These two classes are part of a ClassLibrary project.
The other project has all the web page classes.

My project allows employees to log in using Forms Auth, I do some checking
on the person that is logging in and then after that is good I create an
employee object and that is stored in a session variable.

What I would like is if this employee that logged in gets an error message
at anytime during their use of the web site that the error gets logged with
their userid name. I can log errors and all that, I am logging them to a
database. What I need is just how do I get the error message with the userid
name.

Thanks,
Charles

Nov 19 '05 #1
2 1601
Okay, I'm assuming that somewhere in this employee object stored in a
session variable is the "userid name." If so, and you're creating your own
custom Exception class (why are you inheriting ApplicationExce ption instead
of Exception?), you can create a field named "userid" in the custom
Exception class, and implement a constructor method that includes the
"userid" as a parameter. Then in your Try/Catch (you ARE using Try/Catch,
aren't you???), you do something like the following:

catch (Exception ex)
{
throw new MyCustomExcepti on(ex.Message, ex,
((employee)Sess ion["CurrentEmploye e"]).userid);
}

Of course, what you do with your new Custom Exception is up to you, but I
hope you get the idea.
--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Everybody picks their nose,
But some people are better at hiding it.

"Charles" <Ch*****@discus sions.microsoft .com> wrote in message
news:D4******** *************** ***********@mic rosoft.com...
I need to find a way to share information between two classes, one is an
employee class and the other is a custom error class that inherits from
ApplicationExce ption. These two classes are part of a ClassLibrary
project.
The other project has all the web page classes.

My project allows employees to log in using Forms Auth, I do some checking
on the person that is logging in and then after that is good I create an
employee object and that is stored in a session variable.

What I would like is if this employee that logged in gets an error message
at anytime during their use of the web site that the error gets logged
with
their userid name. I can log errors and all that, I am logging them to a
database. What I need is just how do I get the error message with the
userid
name.

Thanks,
Charles

Nov 19 '05 #2
Thank you for your reply!

Yes there is a "userid name" variable in the employee object.

I am not sure why I am using ApplicationExce ption instead of Exception. The
only reason that I do have is that I found it on an example. Why should I be
using Exception and not ApplicationExce ption?

I wanted to try to avoid implementing a constructor method that includes the
"userid" as a parameter and having other programmers remember how to add the
userid to a Throw New line. But, if there is no other way to do it besides
the way that you explined that I guess I am stuck doing it that way. I am
using a Try/Catch block.

I was hoping for something along these lines,
Public Class InvalidRetrieve Exception
Inherits ApplicationExce ption

Public Sub New()
MyBase.New()

End Sub
Public Sub New(ByVal message As String, ByVal InnerException As
Exception))
'_userName comes from Employee object (somehow)
MyBase.New(mess age & ": " & _userName, InnerException)
WriteToLog(mess age & ": " & _userName, InnerException)
End Sub

End Class

Thanks again,
Charles

"Kevin Spencer" wrote:
Okay, I'm assuming that somewhere in this employee object stored in a
session variable is the "userid name." If so, and you're creating your own
custom Exception class (why are you inheriting ApplicationExce ption instead
of Exception?), you can create a field named "userid" in the custom
Exception class, and implement a constructor method that includes the
"userid" as a parameter. Then in your Try/Catch (you ARE using Try/Catch,
aren't you???), you do something like the following:

catch (Exception ex)
{
throw new MyCustomExcepti on(ex.Message, ex,
((employee)Sess ion["CurrentEmploye e"]).userid);
}

Of course, what you do with your new Custom Exception is up to you, but I
hope you get the idea.
--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Everybody picks their nose,
But some people are better at hiding it.

"Charles" <Ch*****@discus sions.microsoft .com> wrote in message
news:D4******** *************** ***********@mic rosoft.com...
I need to find a way to share information between two classes, one is an
employee class and the other is a custom error class that inherits from
ApplicationExce ption. These two classes are part of a ClassLibrary
project.
The other project has all the web page classes.

My project allows employees to log in using Forms Auth, I do some checking
on the person that is logging in and then after that is good I create an
employee object and that is stored in a session variable.

What I would like is if this employee that logged in gets an error message
at anytime during their use of the web site that the error gets logged
with
their userid name. I can log errors and all that, I am logging them to a
database. What I need is just how do I get the error message with the
userid
name.

Thanks,
Charles


Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
6285
by: Russell Mangel | last post by:
Jeffery Richter makes the following statement in two books, the first was written in 2004, the latter in 2002. "You should not define new exception classes derived from ApplicationException; use Exception instead." ..NET Framework Standard Library Annotated Reference, Volume 1: Base Class Library and Extended Numerics Library (2004) http://www.aw-bc.com/catalog/academic/product/0,1144,0321154894-DS,00.html Exception Management...
4
5512
by: Anders Borum | last post by:
Hello! I am working on improving my threading skills and came across a question. When working with the ReaderWriterLock class, I am getting an unhandled exception if I acquire a WriterLock with a timeout less than the time required to process the code section it protects. The code listed below is just a small application I wrote to check the behavious of the different threading / synchronization techniques. Basically the application...
5
1178
by: NuB | last post by:
I have an app that connects to an excel file and uses it as a DB, the app works fine on my development box but when I move it out to our server it fails, i get this error message: Exception occurred in GenerateBalanceSheet: System.Data.OleDb.OleDbException: The Microsoft Jet database engine could not find the object . Make sure the object exists and that you spell its name and the path name correctly. but the excel file i'm using is...
23
3081
by: VB Programmer | last post by:
Variable scope doesn't make sense to me when it comes to Try Catch Finally. Example: In order to close/dispose a db connection you have to dim the connection outside of the Try Catch Finally block. But, I prefer to dim them "on the fly" only if needed (save as much resources as possible). A little further... I may wish to create a sqlcommand and datareader object ONLY if certain conditions are met. But, if I want to clean these up in the...
20
2885
by: Jason Dravet | last post by:
Some time ago I wrote an application that controls the projectors in our classrooms(turn on, turn off, and volume control). This application is written in VB.net 2003. It was working perfectly until XP SP2 was installed on the PCs. Now when the power on or power off button is pressed the following message is displayed: An unhandled exception has occurred in your application. If you click Continue, the application will ignore this...
3
1327
by: OpticTygre | last post by:
Hey folks, Building my own exception class that inherits from ApplicationException, but includes a few extra properties I create, such as IPAddress and such. I want to define a couple different "New" subroutines to be able to capture all the elements of the error that happened, and the extra data. Problem is, it won't let me do: Public Sub New(ByVal ex as Exception) Me = ex
5
3789
by: Learner | last post by:
Hello, Here is the code snippet I got strucked at. I am unable to convert the below line of code to its equavalent vb.net code. could some one please help me with this? static public List<RoleData> GetRoles() { return GetRoles(null, false); }
1
1293
by: Vivek N | last post by:
I've been working on .Net development. I was wondering if the object browser (the one that comes with Visual Studio.Net 2005) shows the "Protected" fucntions, events etc. I'm not seeing it and so was curious if there is any configuration setting. Thanks, Vivek
22
9252
by: SQACSharp | last post by:
I'm trying to get the control name of an editbox in another window. The following code set the value "MyPassword" in the password EditBox but it fail to return the control name of the EditBox. I'm sure the problem is the way i'm using the sendmessage API, the return string and the lParam return 0....is anybody have a clue? any sendmessage api expert here? public static extern Int32 FindWindow(String lpClassName,String
0
8984
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9530
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9238
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4593
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2206
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.