473,669 Members | 2,460 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Thrown Exception not being Caught

I have a class where I throw a new exception from a method

My calling code (in a different class) is wrapped in a Try/Catch block, but
it's not catching. Instead the IDE is highlighting the ThrowNew Exception
line in the class and saying it was unhandled.

Looking for some help.

Thanks!

Jul 7 '07 #1
4 4141

Terry
My calling code (in a different class) is wrapped in a Try/Catch block,
but it's not catching. Instead the IDE is highlighting the ThrowNew
Exception line in the class and saying it was unhandled.
maybe you are handling specific errors and the one you raise is not one of
them ?
IMHO it is foolish to throw a new exception this way

try
catch ex as exception
throw new exception("bla" )
end try

i do not see the point of catching the error at all in the dll if you
want it to bubbel up to the caller, you could just let the chaining
mechanism handle this , errors are always chained
just as in VB6,
so if you write a handler in a top level of the chain the error will be
catched there with much less overhead and more information about the origin
see my posting and the responses here

http://groups.google.nl/group/micros...0428fc2290c143
Michel


"Terry Olsen" <to

ls****@hotmail. comschreef in bericht
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
>I have a class where I throw a new exception from a method

My calling code (in a different class) is wrapped in a Try/Catch block,
but it's not catching. Instead the IDE is highlighting the ThrowNew
Exception line in the class and saying it was unhandled.

Looking for some help.

Thanks!

Jul 7 '07 #2
I'm not throwing an exception in an exception. Here's a snippet...

Public Class NNTP
Public Sub Stuff
..code removed for brevity
'Tell server that we're a reader
sw.WriteLine("M ODE READER")
GetNntpResponse ()
If rslt <201 And rslt <200 Then
ShutDown()
Throw New Exception(_NNTP Server & ": " & rsltStr)
End If
End Sub
End Class

From my main window, i'm calling it like this:

Dim nntp As New NNTP(ServerName )
Try
nntp.Stuff
Catch ex as Exception
msgbox(ex.messa ge)
Exit Sub
End Try

However, when Sub Stuff throws the exception, the calling code isn't
catching it. Instead, it says that the thrown exception was unhandled.

If you know how to properly do this, i'd appeciate some pointers.

"Michel Posseth [MCP]" <MS**@posseth.c omwrote in message
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
>
Terry
>My calling code (in a different class) is wrapped in a Try/Catch block,
but it's not catching. Instead the IDE is highlighting the ThrowNew
Exception line in the class and saying it was unhandled.

maybe you are handling specific errors and the one you raise is not one of
them ?
IMHO it is foolish to throw a new exception this way

try
catch ex as exception
throw new exception("bla" )
end try

i do not see the point of catching the error at all in the dll if you
want it to bubbel up to the caller, you could just let the chaining
mechanism handle this , errors are always chained
just as in VB6,
so if you write a handler in a top level of the chain the error will be
catched there with much less overhead and more information about the
origin
see my posting and the responses here

http://groups.google.nl/group/micros...0428fc2290c143
Michel


"Terry Olsen" <to

ls****@hotmail. comschreef in bericht
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
>>I have a class where I throw a new exception from a method

My calling code (in a different class) is wrapped in a Try/Catch block,
but it's not catching. Instead the IDE is highlighting the ThrowNew
Exception line in the class and saying it was unhandled.

Looking for some help.

Thanks!


Jul 7 '07 #3
I would guess one of two things are happening:
1 - You're calling "Stuff" from inside the constructure or your NNTP class.
With you constructing your NNTP class outside the try/catch, the exception
is being propigated.

2 - You have "Break on all Exceptions" turned on. This means each time an
exception is thrown, you break into the debugger. Look at this via
"Ctrl-Alt-E" at design time, and make sure the settings are all default.

There area also a few exception types that you really can't catch - for
example if you run out of memory, or run out of stack space, it's not always
possible to catch these. I really doubt you're running into that here
though.

--
Chris Mullins, MCSD.NET, MCPD:Enterprise , Microsoft C# MVP
http://www.coversant.com/blogs/cmullins

"Terry Olsen" <to******@hotma il.comwrote in message
news:u%******** ********@TK2MSF TNGP04.phx.gbl. ..
I'm not throwing an exception in an exception. Here's a snippet...

Public Class NNTP
Public Sub Stuff
..code removed for brevity
'Tell server that we're a reader
sw.WriteLine("M ODE READER")
GetNntpResponse ()
If rslt <201 And rslt <200 Then
ShutDown()
Throw New Exception(_NNTP Server & ": " & rsltStr)
End If
End Sub
End Class

From my main window, i'm calling it like this:

Dim nntp As New NNTP(ServerName )
Try
nntp.Stuff
Catch ex as Exception
msgbox(ex.messa ge)
Exit Sub
End Try

However, when Sub Stuff throws the exception, the calling code isn't
catching it. Instead, it says that the thrown exception was unhandled.

If you know how to properly do this, i'd appeciate some pointers.

"Michel Posseth [MCP]" <MS**@posseth.c omwrote in message
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
>>
Terry
>>My calling code (in a different class) is wrapped in a Try/Catch block,
but it's not catching. Instead the IDE is highlighting the ThrowNew
Exception line in the class and saying it was unhandled.

maybe you are handling specific errors and the one you raise is not one
of them ?
IMHO it is foolish to throw a new exception this way

try
catch ex as exception
throw new exception("bla" )
end try

i do not see the point of catching the error at all in the dll if you
want it to bubbel up to the caller, you could just let the chaining
mechanism handle this , errors are always chained
just as in VB6,
so if you write a handler in a top level of the chain the error will be
catched there with much less overhead and more information about the
origin
see my posting and the responses here

http://groups.google.nl/group/micros...0428fc2290c143
Michel


"Terry Olsen" <to

ls****@hotmail. comschreef in bericht
news:%2******* *********@TK2MS FTNGP02.phx.gbl ...
>>>I have a class where I throw a new exception from a method

My calling code (in a different class) is wrapped in a Try/Catch block,
but it's not catching. Instead the IDE is highlighting the ThrowNew
Exception line in the class and saying it was unhandled.

Looking for some help.

Thanks!



Jul 7 '07 #4
IMHO it is foolish to throw a new exception this way
>
try
catch ex as exception
throw new exception("bla" )
end try
This example would not be a good example, but sometimes you want to
catch an exception and then throw a different exception, perhaps a
custom exception with additional information in it. In which case,
you would wrap the original exception in your new one:

Try
'Something that might throw and exception
Catch Ex As Exception
Throw New MyCustomExcepti onWithAdditiona lInformation(Ex )
End Try

Chris

Jul 9 '07 #5

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

Similar topics

1
15961
by: Jorge Cecílio | last post by:
Hi all! I've a (beginner) problem accessing a method on another class. When I execute a method such as: //response to a swing button public void actionPerformed(ActionEvent event) {
9
1574
by: fabio de francesco | last post by:
Hi, I would like to know why objects that are thrown to be caught are copy-constructed more than once. I have seen this behaviour after running the following simple program that is an exercise (adapted from F.Brokken C++ Annotations) only to see constructors at work: /* exception.cpp */
10
8560
by: Cool Guy | last post by:
Consider: void Start() { if (!TryToDoSomething()) ShowErrorMessage(); }
5
1946
by: Mark Kamoski | last post by:
Hi Everyone-- How can one get the line number of where an error was thrown and/or caught? For example, note the following, for use at any given point in a piece of code: ....to get the current Assembly's name, one can use this... System.Reflection.Assembly.GetExecutingAssembly().GetName().Name
4
1445
by: chopsnsauce | last post by:
Here is the problem. I'm opening a form that Throw's an error in the Load event and the method thant opens the form has a try..Catch to Catch the error that is thrown in the load event. This works fine running through the design-time enviroment. But if I run the .EXE it says Unhandled Exception and quits. WHY? How do I fix this???
4
2522
by: Michael Rodriguez | last post by:
I have a data layer in a dll class. If I manually throw an exception in that data layer, the generic Application.OnThreadException in my UI does not catch it nor does it display any message whatsoever. The user is totally unaware of the error. How can I catch these errors without having to manually try...catch each one? Thanks,
1
1198
by: Mark | last post by:
We have an internal web service that intentionally allows raw Exceptions to be thrown to the clients that consume it. This web service is consumed by internal ASP.NET applications. When the exception is caught by an ASP.NET application, the amount of detail in the SOAP exception is limited. There is no inner exception. However, if the exception is interegated by the webservice before its thrown, it contains tons of information,...
7
2288
by: Chris | last post by:
Hello all... I have a program with the following structure (all classes mentioned are of my own creation, and none of the classes contain try or catch blocks): - main() consists of a large try block with several catch blocks I will describe below. main(), within the try block, declares, and implicitly default-constructs, a variable (object) of class AppDBConn.
1
2356
by: sudhivns | last post by:
Function F1() throwing an exception of type say int. But this exception is not getting caught. piece of code is: try { .... F1() ..... } catch(int x) {
0
8465
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...
1
8588
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8658
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...
0
7407
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6210
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
4206
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
4386
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2797
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2032
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.