Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > catch(Exception* e){ throw;} generate error

Reply
Thread Tools

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

 
 
Daimler
Guest
Posts: n/a
 
      01-25-2007
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

















 
Reply With Quote
 
 
 
 
Colander
Guest
Posts: n/a
 
      01-25-2007
On Jan 25, 2:09 pm, "Daimler" <daimle...@yahoo.com.sg> wrote:
> 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

 
Reply With Quote
 
 
 
 
benben
Guest
Posts: n/a
 
      01-25-2007
Daimler wrote:
> 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
 
Reply With Quote
 
john_andronicus@hotmail.com
Guest
Posts: n/a
 
      01-25-2007


On 25 Jan, 13:09, "Daimler" <daimle...@yahoo.com.sg> wrote:
> 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

 
Reply With Quote
 
peter koch
Guest
Posts: n/a
 
      01-25-2007


On Jan 25, 2:09 pm, "Daimler" <daimle...@yahoo.com.sg> wrote:
> 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

 
Reply With Quote
 
Ron Natalie
Guest
Posts: n/a
 
      01-25-2007
peter koch wrote:

>> ---------------------------------------------------------------------------*---------------

> 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) { ...
 
Reply With Quote
 
benben
Guest
Posts: n/a
 
      01-25-2007
Ron Natalie wrote:
> peter koch wrote:
>
>>> ---------------------------------------------------------------------------*---------------
>>>

>> 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) { ...


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

Regards,
Ben
 
Reply With Quote
 
Daimler
Guest
Posts: n/a
 
      01-26-2007
thank you everyone for your advise.

found the asnwers.

using __try and __except to discard the exception dialog box.

thanks again! -_-

daimler_smiles

"Daimler" <> wrote in message
news:epa79i$841$...
>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
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Failed to generate a user instance of SQL Server. Only an integratedconnection can generate a user instance. Harlan Messinger ASP .Net 2 03-28-2010 06:51 PM
crypto key generate rsa error Michael W. Hubbard Cisco 5 08-08-2008 01:08 AM
How to generate warnings when How generate a warning when int is converted to bool or vice versa? PengYu.UT@gmail.com C++ 3 04-06-2006 11:24 PM
How to generate variable labels for same component within a generate loop Weng Tianxiang VHDL 5 02-16-2006 01:45 PM
Error Generate Statement Isaac VHDL 3 08-07-2003 07:24 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57