473,387 Members | 1,540 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Exception Catch but dont throw

I cant seem to find an example on how to do something, ( vb2005.express )

i have a

Try
ListeningSerialPort.Open()
TestText.Enabled = True
Catch ex As Exception
'Debug.WriteLine(ex.Message)
End Try

<morecodehere>...

statement, and what I am tryign to do is Catch the exception ( which it
does ) but i dont want to throw it anywhere.

How do I get this try catch to continue gracefully so if an exception is
caught, the "more code here" gets executed and continues on - the user never
sees that an exception was hit and they do not know the difference?

Currently when I compile / and create a setup.exe with the publish and
install it, the program hits a fatal exception -displays it to the user and
fails. If I run the same program in vb.net express, then this does not
happen, it shows the exception in the immediate window but lets me continue.
Am I missing something with the Try Catch statement ?

I hope that makes sence.

Miro
Aug 1 '07 #1
3 3456
On Aug 1, 12:03 pm, "Miro" <miron...@golden.netwrote:
I cant seem to find an example on how to do something, ( vb2005.express )

i have a

Try
ListeningSerialPort.Open()
TestText.Enabled = True
Catch ex As Exception
'Debug.WriteLine(ex.Message)
End Try

<morecodehere>...

statement, and what I am tryign to do is Catch the exception ( which it
does ) but i dont want to throw it anywhere.

How do I get this try catch to continue gracefully so if an exception is
caught, the "more code here" gets executed and continues on - the user never
sees that an exception was hit and they do not know the difference?

Currently when I compile / and create a setup.exe with the publish and
install it, the program hits a fatal exception -displays it to the user and
fails. If I run the same program in vb.net express, then this does not
happen, it shows the exception in the immediate window but lets me continue.
Am I missing something with the Try Catch statement ?

I hope that makes sence.

Miro
Your current try catch should "continue gracefully" on any Exception
object - so I'm not sure why it isn't. You might try omitting the "ex
as exception" part - this will cause it to trap all but a few really
nasty (and normally non-recoverable) exceptions.

i.e.

Try
...
Catch
...
End Try

Also, are you sure the exception is from this method? Perhaps you are
hitting a security exception or something before you make it to the
above code?

Thanks,

Seth Rowe

Aug 1 '07 #2
The "Catch" on its own did not work.

I have changed it to be this and i still get the error.
====
Debug.WriteLine("b4exp")
Try
ListeningSerialPort.Close()
Catch extry As System.UnauthorizedAccessException
Debug.WriteLine("cought it")
Catch ex As Exception
Debug.WriteLine("other caught it")
End Try
Debug.WriteLine("aftb4exp")
===
my output is as follows in the immedate window
b4exp
A first chance exception of type 'System.UnauthorizedAccessException'
occurred in System.dll
cought it
aftb4exp
====

I cant seem to get around it from it throwing that exception. Any other
ideas?

What I am basically doing is i have a proximety scanner hooked up thru a usb
to my computer.
In the begining what I do is
if serial.isopen() = false then serial.open()

then what I do is i unplug the usb.
The problem is that when I unplug the usb isopen still returns True, so
what I do is I have a timer and every so many seconds and i then
Dim CurrentAvailPorts As Array = SerialPort.GetPortNames()
and compare what port names are available to the ones I THINK that are open,
and if they are actaully not anymore ( by GetPortNames() ) I try to close
them. Thats where the error is occuring.

That way, every so many seconds...when GetPortNames does return my ComPort
that was opened and is available again - I re-open it.

The Part that is failing is the "closing" of the port when the usb is
unplugged.
Any other Ideas?

Thanks

Miro

"rowe_newsgroups" <ro********@yahoo.comwrote in message
news:11**********************@l70g2000hse.googlegr oups.com...
On Aug 1, 12:03 pm, "Miro" <miron...@golden.netwrote:
>I cant seem to find an example on how to do something, ( vb2005.express )

i have a

Try
ListeningSerialPort.Open()
TestText.Enabled = True
Catch ex As Exception
'Debug.WriteLine(ex.Message)
End Try

<morecodehere>...

statement, and what I am tryign to do is Catch the exception ( which it
does ) but i dont want to throw it anywhere.

How do I get this try catch to continue gracefully so if an exception is
caught, the "more code here" gets executed and continues on - the user
never
sees that an exception was hit and they do not know the difference?

Currently when I compile / and create a setup.exe with the publish and
install it, the program hits a fatal exception -displays it to the user
and
fails. If I run the same program in vb.net express, then this does not
happen, it shows the exception in the immediate window but lets me
continue.
Am I missing something with the Try Catch statement ?

I hope that makes sence.

Miro

Your current try catch should "continue gracefully" on any Exception
object - so I'm not sure why it isn't. You might try omitting the "ex
as exception" part - this will cause it to trap all but a few really
nasty (and normally non-recoverable) exceptions.

i.e.

Try
...
Catch
...
End Try

Also, are you sure the exception is from this method? Perhaps you are
hitting a security exception or something before you make it to the
above code?

Thanks,

Seth Rowe

Aug 1 '07 #3
I'm not sure what is the exact problem.

Debug messages are show in the debug console to developers (my understanding
is that you don't want to see the exception message in the debug output
???). It doesn't mean an end user would see this in the final build.

The exception is ALWAYS throw. What matter is if it is handled (in which
case you do whatever you want includuing not showing it to the end user) or
undhandled (in which case the .NET runtime will show the error) ? The
exception always happend and the dbeug outpuit always show that an exception
occured.

Not familiar with this class but always prefer a check to throwing exception
(tha is if you have a method/proerty that allows to check the port status
prefer checking the status so that you know if you can close to catching
exceptions).

--
Patrice

"Miro" <mi******@golden.neta écrit dans le message de news:
%2****************@TK2MSFTNGP06.phx.gbl...
The "Catch" on its own did not work.

I have changed it to be this and i still get the error.
====
Debug.WriteLine("b4exp")
Try
ListeningSerialPort.Close()
Catch extry As System.UnauthorizedAccessException
Debug.WriteLine("cought it")
Catch ex As Exception
Debug.WriteLine("other caught it")
End Try
Debug.WriteLine("aftb4exp")
===
my output is as follows in the immedate window
b4exp
A first chance exception of type 'System.UnauthorizedAccessException'
occurred in System.dll
cought it
aftb4exp
====

I cant seem to get around it from it throwing that exception. Any other
ideas?

What I am basically doing is i have a proximety scanner hooked up thru a
usb to my computer.
In the begining what I do is
if serial.isopen() = false then serial.open()

then what I do is i unplug the usb.
The problem is that when I unplug the usb isopen still returns True, so
what I do is I have a timer and every so many seconds and i then
Dim CurrentAvailPorts As Array = SerialPort.GetPortNames()
and compare what port names are available to the ones I THINK that are
open, and if they are actaully not anymore ( by GetPortNames() ) I try to
close them. Thats where the error is occuring.

That way, every so many seconds...when GetPortNames does return my ComPort
that was opened and is available again - I re-open it.

The Part that is failing is the "closing" of the port when the usb is
unplugged.
Any other Ideas?

Thanks

Miro

"rowe_newsgroups" <ro********@yahoo.comwrote in message
news:11**********************@l70g2000hse.googlegr oups.com...
>On Aug 1, 12:03 pm, "Miro" <miron...@golden.netwrote:
>>I cant seem to find an example on how to do something, (
vb2005.express )

i have a

Try
ListeningSerialPort.Open()
TestText.Enabled = True
Catch ex As Exception
'Debug.WriteLine(ex.Message)
End Try

<morecodehere>...

statement, and what I am tryign to do is Catch the exception ( which it
does ) but i dont want to throw it anywhere.

How do I get this try catch to continue gracefully so if an exception is
caught, the "more code here" gets executed and continues on - the user
never
sees that an exception was hit and they do not know the difference?

Currently when I compile / and create a setup.exe with the publish and
install it, the program hits a fatal exception -displays it to the user
and
fails. If I run the same program in vb.net express, then this does not
happen, it shows the exception in the immediate window but lets me
continue.
Am I missing something with the Try Catch statement ?

I hope that makes sence.

Miro

Your current try catch should "continue gracefully" on any Exception
object - so I'm not sure why it isn't. You might try omitting the "ex
as exception" part - this will cause it to trap all but a few really
nasty (and normally non-recoverable) exceptions.

i.e.

Try
...
Catch
...
End Try

Also, are you sure the exception is from this method? Perhaps you are
hitting a security exception or something before you make it to the
above code?

Thanks,

Seth Rowe


Aug 1 '07 #4

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

Similar topics

2
by: ma740988 | last post by:
The hierachy for standard exception lists: bad_alloc, bad_cast, bad_typeid, logic_error, ios_base::failure, runtime_error and bad_exception runtime_error and logic_error has subsets. The...
5
by: Kevin Jackson | last post by:
In the following code snippet, will the finally block be executed when the throw is executed in the catch block???? I'm assuming it will. catch (Exception e) { // if...
3
by: David | last post by:
Hi, Ive been trying to work this out for the past 2 days now and im not getting anywhere fast. The problem i have is that i am using Asynchronous sockets to create a Socket Client library....
44
by: craig | last post by:
I am wondering if there are some best practices for determining a strategy for using try/catch blocks within an application. My current thoughts are: 1. The code the initiates any high-level...
2
by: Mark Traudt | last post by:
The following managed C++ function is called from an unmanaged C++ DLL: double Divide( double num, double denom ) { if( denom == 0.0 ) throw new std::exception( "divide by zero" ); return num...
2
by: Rajeev Soni | last post by:
Hi, Considering the scenario for handling exceptions in Web Application where we have Presentation layer, Business layer and Data Access layer; if there any exception is occurred in DAL, what is...
4
by: Rob Richardson | last post by:
Greetings! I am working on an application that targets a Pocket PC running Windows CE and SQL Server CE. Almost all functions in the application use a Try block with a Catch block that looks...
7
by: Sek | last post by:
Hi Folks! I was pondering over a code and noticed that exception handlers were present in the private, protected as well as public methods. And, ofcourse, public methods were calling priv/prot...
4
by: shapper | last post by:
Hello, I have a function which communicates with a database: Public Overloads Sub Create(ByVal name As String, _ ByVal comment As String) Try Dim dbBlog As Database =...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.