Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

Dear All,

 

 

I'm developing a system at the moment that is divided into separate files for different class types. One of those files contains all of the exceptions that I've defined as Public Shared exceptions.

 

My problem is, however, that I can't seem to access them from other classes.

 

When I first used this method of storing exceptions in class sets like this they worked fine - I was able to throw and detect they various forms of exception that were defined. This seems to have gone wrong, though, and intelisense doesn't expand the class to show the underlying exceptions. In fact, it doesn't even recognise the class...

 

Here's the code, can anyone shine any light on this for me, please...

 

File 1 - ehExceptions.vb

Namespace EventHorizon.Exceptions

   'General interface exceptions...
   Public Class InterfaceExceptions

   End Class

   'Database/data exchange exceptions...
   Public Class DatabaseExceptions

       'Initialisation failed...
       Public Shared ehInitialisationFailedException As New System.Exception("InitialisationFailed")
       'Query execution failed...
       Public Shared ehExecutionFailedException As New System.Exception("QueryExecutionFailed")
       'Invalid parameter...
       Public Shared ehInvalidParameterValueException As New System.Exception("InvalidParameterValue")

   End Class

   'PDA related exceptions...
   Public Class PDAExceptions

       'PDA not connected...
       Public Shared ehNoPDAException As New System.Exception("NoPDADetected")
       'Other PDA exceptions...
       Public Shared ehPDABadConnectionException As New System.Exception("BadPDAConnection")

   End Class

   'System exceptions...
   Public Class SystemExceptions

       'Index out of range...
       Public Shared ehIndexOutOfRangeException As New System.IndexOutOfRangeException("IndexOutOfRange")
       'Invalid property...
       Public Shared ehInvalidPropertyException As New System.Exception("InvalidProperty")
       'Property not defined...
       Public Shared ehUndefinedPropertyException As New System.Exception("UndefinedProperty")

   End Class

   'Generic exceptions used by all classes/modules...
   Public Class GenericExceptions

   End Class

End Namespace

 

File 2 - SecurityClasses.vb

Namespace EventHorizon.ehSecurity

   'The primary user class for EventHorizon Security...
   Public Class ehUser
       'Private properties...
       Private _UserId As Long
       Private _Username As String
       Private _Password As String
       Private _Roles As ehRoleCollection

   End Class

   'The Role Colelction class...
   Public Class ehRoleCollection
       Inherits System.Collections.CollectionBase

       Public Sub Add(ByVal paramItem As ehRole)
           list.Add(paramItem)
       End Sub

       Public Sub Remove(ByVal paramItem As Integer)
           If paramItem > 0 And paramItem <= list.Count - 1 Then
               list.Remove(paramItem)
           Else
               Throw systemexceptions.ehindexoutofrangeexception
           End If
       End Sub
   End Class

   Public Class ehRole

   End Class

End Namespace

 

PS: I've even tried referring to the namespace, but this doesn't produce any results, either! :confused:

 

Also, all files are within the same solution and project.

 

 

Paul.

Edited by mandelbrot
Posted

Ah, ok - I've found it. I've defined all the classes in their own namespaces, appropriate to their function. This seems to be preventing them from being detected for some reason.

 

Does anyone know why?

 

 

Paul.

  • Administrators
Posted
That's what namespaces are there for - to seperate classes into logical groups. If you need to access a class from a particular namespace then you will either have to refer to the class using it's namespace or import the namespace at the top of the code file.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

Yes, but I should be able to refer to the namespace via the code by fully qualifying the path...

Throw EventHorizon.ehExceptions.SystemExceptions.ehIndexOutOfRangeException

...for instance, but this didn't seem to be happening, and I can't understand why...

Posted

Ah - scrub that - I've found out why it's not working properly...

 

The system is based on a Windows Forms app chasis, and I'm missing out the initial EventHorizonW32 namespace...

 

*mandelbrot slaps his forehead and looks up at the stars*

 

Thanks for your input, PD! ;)

 

 

Paul.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...