Click here to Skip to main content
15,890,512 members
Home / Discussions / Visual Basic
   

Visual Basic

 
Questionaccess MDB database help Pin
Dave McCool5-Feb-09 3:16
Dave McCool5-Feb-09 3:16 
AnswerRe: access MDB database help Pin
Dominick Marciano5-Feb-09 4:21
professionalDominick Marciano5-Feb-09 4:21 
AnswerRe: access MDB database help Pin
Rupesh Kumar Swami5-Feb-09 4:22
Rupesh Kumar Swami5-Feb-09 4:22 
Questionretrive field value into combobox Pin
vijay24825-Feb-09 2:42
vijay24825-Feb-09 2:42 
AnswerRe: retrive field value into combobox Pin
Rupesh Kumar Swami5-Feb-09 3:11
Rupesh Kumar Swami5-Feb-09 3:11 
Question[Message Deleted] Pin
εїзεїзεїз5-Feb-09 2:07
εїзεїзεїз5-Feb-09 2:07 
AnswerRe: Grid View Control Pin
Henry Minute5-Feb-09 9:16
Henry Minute5-Feb-09 9:16 
QuestionWhere to put try / catch blocks when dealing with classes Pin
maxnuggets5-Feb-09 0:55
maxnuggets5-Feb-09 0:55 
Hi,

Having worked as a VB6 programmer, and dealing mostly with events from forms and modules etc. I'm a little confused as to where to do exception handling with a class in .NET.

I have a class I've written that (amongst other things) sends a HttpWebRequest to a server and I want it to read the XML feed from the server. But where exactly do I handle the WebException that might occur? Should I put the try/catch into the actual class method that send the HttpWebRequest or should it be in the module code that calls the Function that will send the web request? See below for a brief example of what I mean.

Class MyClass
...
...
...
   Sub GetXmlFromServer()
    Try
      ' send request
    Catch wex As System.Net.WebException
    end try
   End Sub
...
End Class

' in a module
Sub GetXml()
  Dim mc as new MyClass()

  mc.GetXmlFromServer()
End Sub


Or

Class MyClass
...
...
...
   Sub GetXmlFromServer()
 
      ' send request
      ' etc etc
   End Sub
...
End Class

' in a module
Sub GetXml()
  Dim mc as new MyClass()
  try
    mc.GetXmlFromServer()
  Catch wex As System.Net.WebException
  End Try
End Sub


Personally I don't think I should put the exception handling in the class and that it should be handled in the sub/function (in a form or module) that calls the class method. But I'd like to know the
correct way to go about it.

Thanks Smile | :)

Max
AnswerRe: Where to put try / catch blocks when dealing with classes Pin
Johan Hakkesteegt5-Feb-09 2:09
Johan Hakkesteegt5-Feb-09 2:09 
GeneralRe: Where to put try / catch blocks when dealing with classes Pin
maxnuggets5-Feb-09 2:22
maxnuggets5-Feb-09 2:22 
GeneralRe: Where to put try / catch blocks when dealing with classes Pin
Johan Hakkesteegt5-Feb-09 3:04
Johan Hakkesteegt5-Feb-09 3:04 
AnswerRe: Where to put try / catch blocks when dealing with classes Pin
riced5-Feb-09 4:43
riced5-Feb-09 4:43 
GeneralRe: Where to put try / catch blocks when dealing with classes Pin
supercat95-Feb-09 6:28
supercat95-Feb-09 6:28 
QuestionModifying a window service Pin
sohaib_a4-Feb-09 22:58
sohaib_a4-Feb-09 22:58 
AnswerRe: Modifying a window service Pin
Dave Kreskowiak5-Feb-09 2:23
mveDave Kreskowiak5-Feb-09 2:23 
Questionvb express list box Pin
steve moorley4-Feb-09 22:49
steve moorley4-Feb-09 22:49 
AnswerRe: vb express list box Pin
Rupesh Kumar Swami4-Feb-09 22:57
Rupesh Kumar Swami4-Feb-09 22:57 
Questioncompiling what was compiled before Pin
Member 42169604-Feb-09 22:36
Member 42169604-Feb-09 22:36 
AnswerRe: compiling what was compiled before Pin
Alan N5-Feb-09 0:25
Alan N5-Feb-09 0:25 
GeneralRe: compiling what was compiled before Pin
Member 42169605-Feb-09 0:40
Member 42169605-Feb-09 0:40 
GeneralRe: compiling what was compiled before Pin
Dave Kreskowiak5-Feb-09 2:20
mveDave Kreskowiak5-Feb-09 2:20 
GeneralRe: compiling what was compiled before Pin
Member 42169605-Feb-09 4:58
Member 42169605-Feb-09 4:58 
GeneralRe: compiling what was compiled before Pin
Dave Kreskowiak5-Feb-09 5:31
mveDave Kreskowiak5-Feb-09 5:31 
GeneralRe: compiling what was compiled before Pin
EliottA5-Feb-09 6:06
EliottA5-Feb-09 6:06 
GeneralRe: compiling what was compiled before Pin
Member 42169605-Feb-09 20:52
Member 42169605-Feb-09 20:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.