![]() |
catch(Exception* e){ throw;} generate error
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 |
Re: catch(Exception* e){ throw;} generate error
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 |
Re: catch(Exception* e){ throw;} generate error
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 |
Re: catch(Exception* e){ throw;} generate error
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 |
Re: catch(Exception* e){ throw;} generate error
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 |
Re: catch(Exception* e){ throw;} generate error
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) { ... |
Re: catch(Exception* e){ throw;} generate error
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 |
Re: catch(Exception* e){ throw;} generate error
thank you everyone for your advise.
found the asnwers. using __try and __except to discard the exception dialog box. thanks again! -_- daimler_smiles "Daimler" <daimler_6@yahoo.com.sg> wrote in message news:epa79i$841$1@mawar.singnet.com.sg... >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 > > > > > > > > > > > > > > > > > |
| All times are GMT. The time now is 04:29 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.