catch(Exception* e){ throw;} generate error

D

Daimler

i am using visual c++ 2005 clr window form with

try and catch a serial port readline.

the codes are as follows: -

try{

Form1::textBox1->Text = Form1::serialPort1->ReadLine();

}

catch(Exception* e){ throw;}



------------------------------------------------------------------------------------------

the debug generate an error.

what is wrong?

please help!

daimler_trying_hard
 
C

Colander

i am using visual c++ 2005 clr window form with

try and catch a serial port readline.

the codes are as follows: -

try{

Form1::textBox1->Text = Form1::serialPort1->ReadLine();

}catch(Exception* e){ throw;}

------------------------------------------------------------------------------------------

the debug generate an error.

what is wrong?

Most probably the ReadLine() fails and trows an error that your catch
will catch
but there it gets retrown and probably no other catch exists so an
uncaught exeption
exists and your debugger will tell you this is an error.

If this is not the case, I advise you to take your problem to an MS
related
newsgroup, they will understand better what the ReadLine() and other
elements
of your code are doing, we only talk about 'pure' C++ here.

Good luck,
Bas
 
B

benben

Daimler said:
i am using visual c++ 2005 clr window form with

try and catch a serial port readline.

the codes are as follows: -

try{

Form1::textBox1->Text = Form1::serialPort1->ReadLine();

}

catch(Exception* e){ throw;}



------------------------------------------------------------------------------------------

the debug generate an error.

what is wrong?

We don't know. What error do you get? Why are you catching a pointer? By
rethrowing the exception you are allowing it to propagate. So if there
is nothing else to catch the exception the stack unwinding will pass
through main() then crashes the program.
please help!

You need to post a minimal program written in ISO C++ without 3rd party
library to demonstrate your problem. Then we can pinpoint it for you. If
you find this hard to do, maybe it's just not a language problem and you
should try elsewhere.
daimler_trying_hard

Regards,
Ben
 
J

john_andronicus

i am using visual c++ 2005 clr window form with

try and catch a serial port readline.

the codes are as follows: -

try{

Form1::textBox1->Text = Form1::serialPort1->ReadLine();

}catch(Exception* e){ throw;}

------------------------------------------------------------------------------------------

the debug generate an error.

what is wrong?

Well taking a few wild guesses.

Form1::serialPort1 is a null or garbage pointer.

Form1::textBox1 is a null or garbage pointer

The object pointed to by Form1::serialPort1 has not been 'connected' to
a serial port.

etc. etc.

Why do you complain that 'throw' generates an error, isn't that what it
is supposed to do? What are you expecting to happen if ReadLine fails?

John
 
P

peter koch

i am using visual c++ 2005 clr window form with

try and catch a serial port readline.

Note that this forum is for standard C++ and not extensions or
languages similar to C++.
the codes are as follows: -

try{

Form1::textBox1->Text = Form1::serialPort1->ReadLine();

}catch(Exception* e){ throw;}

---------------------------------------------------------------------------­---------------
If the above is "pure C++", the code is technically healthy and should
not generate an error. One should question thoush, why you catch by
pointer and not by (const) reference.
the debug generate an error.

what is wrong?
Depends on what error - you are not at all clear about this. I suggest
you create a minimal working sample (in C++!) and show it to us. In
that process you often discover the error by yourself.

/Peter
 
R

Ron Natalie

peter said:
If the above is "pure C++", the code is technically healthy and should
not generate an error. One should question thoush, why you catch by
pointer and not by (const) reference.

One possibility is the pointer he is throwing refers to an object that
has ceased to be:

BAD:
try {
Exception x;
throw &x;
} catch (Exception* x) { ...
 
B

benben

Ron said:
One possibility is the pointer he is throwing refers to an object that
has ceased to be:

BAD:
try {
Exception x;
throw &x;
} catch (Exception* x) { ...

Well I guess you can safely throw bad pointers as long as you don't
dereference them.

Regards,
Ben
 
D

Daimler

thank you everyone for your advise.

found the asnwers.

using __try and __except to discard the exception dialog box.

thanks again! -_-

daimler_smiles
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top