|
clawton wrote: Are there any rules of thumb, guidelines, issues with, etc... about having a return in a catch block
Should be fine.
clawton wrote: Step through the code in debugger. On several systems, I see the debug statement indicator move onto the line with "return 1".
Yeah, that happens - it all depends how the debug information's been distributed through the code. Is it in Release or Debug mode? Debugging in Release mode is...interesting.
clawton wrote: The disassembly code is very strange indeed
In what sense?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Stuart Dootson wrote:
Is it in Release or Debug mode?
Debug mode.
Stuart Dootson wrote:
clawton wrote:
The disassembly code is very strange indeed
In what sense?
Well, I see the line with "return 1" in there twice...
Pasting from the dissassembly output window:
std::vector<int> v;
004131C6 lea ecx,[ebp-34h]
004131C9 call std::vector<int,std::allocator<int> >::vector<int,std::allocator<int> > (4110C3h)
004131CE mov dword ptr [ebp-4],0
try {
004131D5 mov byte ptr [ebp-4],1
v.push_back(1);
004131D9 mov dword ptr [ebp-118h],1
004131E3 lea eax,[ebp-118h]
004131E9 push eax
004131EA lea ecx,[ebp-34h]
004131ED call std::vector<int,std::allocator<int> >::push_back (4119B5h)
004131F2 jmp $LN5 (413211h)
} catch (std::exception &) {
return 1;
004131F4 mov dword ptr [ebp-10Ch],1
004131FE mov dword ptr [ebp-4],0
00413205 mov eax,offset $LN9 (41321Ah)
0041320A ret
void CCatchTestDlg::OnBnClickedOk()
{
Test(1,0);
}
int CCatchTestDlg::Test(int foo, unsigned char * goo)
{
std::vector<int> v;
try {
v.push_back(1);
} catch (std::exception &) {
return 1;
}
0041320B mov eax,offset $LN5 (413211h)
00413210 ret
} catch (std::exception &) {
return 1;
00413211 mov dword ptr [ebp-4],0
00413218 jmp $LN9+17h (413231h)
$LN9:
0041321A mov dword ptr [ebp-4],0FFFFFFFFh
00413221 lea ecx,[ebp-34h]
00413224 call std::vector<int,std::allocator<int> >::~vector<int,std::allocator<int> > (41192Eh)
00413229 mov eax,dword ptr [ebp-10Ch]
0041322F jmp $LN9+54h (41326Eh)
if (v.size()) {
00413231 lea ecx,[ebp-34h]
00413234 call std::vector<int,std::allocator<int> >::size (4115A5h)
|
|
|
|
|
I think I see 'return 1;' three times...
I think the reason is that there's more code thn you expect round an exception handler (unhandled case, handled case, no exception case) and the disassembler puts in hte source code context for each one.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I think I see 'return 1;' three times...
I think the reason is that there's more code thn you expect round an exception handler (unhandled case, handled case, no exception case) and the disassembler puts in the source code context for each one.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hi,
some people insist on having just one return statement in a function; that makes having it in a
catch block rather hard. If you feel more lenient, go ahead.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
I guess there's nothing so wrong with returning -1 from catch block. But I personally, just HATE it.
OK,. what country just started work for the day ? The ASP.NET forum is flooded with retarded questions. -Christian Graus
Best wishes to Rexx[^]
|
|
|
|
|
Hi Clawton
I have the same issue. It seems the same happens in VC2010 too.
First I tried to find out what's wrong in my code, but a few days trial failed and I came here after searching internet. Now I see it's not my code problem but the compiler.
Have you found out how to make the debugger not step into the 'return 1'?
All the replies below do not clearly commented why it happens and how to overcome it.
If you summarize your answers that'd be great.
thx
HaeRim
|
|
|
|
|
After seeing the replies and studying the assemble code, I ended up convencing myself that all was operating as it should and I need to just be aware of it.
Although I do try to code a bit differently - i.e. not put a return in a catch block.
Chris
|
|
|
|
|
Hello,
I am working on a project where I need to figure out the MAC address associated with a particular IP, in code. I could do this from the command line, and am tempted to have the program just do that...but would rather deal with the raw sockets to keep everything in one program.
Ideally I need a way to send an arp request out and capture the return response. I would also like to use as FEW non-standard libraries as possible, as the SW will be ported to a PPC once it is "working".
Any ideas or pointers of how I should go about doing this would be GREATLY appreciated. Thanks for your help in advance!
|
|
|
|
|
thelonesquirrely wrote: Any ideas or pointers of how I should go about doing this would be GREATLY appreciated.
Maybe this will help[^]
|
|
|
|
|
funny. clever even. not doing msdn development. fedora core 10.
|
|
|
|
|
thelonesquirrely wrote: funny. clever even
That's nothing, watch this, nothing up my sleeve PRESTO![^]
|
|
|
|
|
Almost had me there. I thought there was gonna be a bunny . The raw sockets use MAC to MAC. And I have the IP/port. I need to get the MAC.
ps. I was gonna make some snide comment about reading the headline, but then i realized i mis-typed it. oops .
|
|
|
|
|
If there's a command line way of doing it, can't you have a peek at the source of the comamnd that does it?
If the IP is of a local network adaptor, you can probably use an ioctl on the socket to get the MAC address (see this bit of code[^]).
If it's remote, then you either need to decode a packet coming back from the remote address (it ill contain the MAC address in the ethernet part of the packet) or search through the ARP cache...
From what I can see, this book[^] is the definitive source for this stuff. It's on Safari and looks to have everything you'd want.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
i need to drawline on picture box in MFC/C++
how can do it?
please give some tip or hint to me
thanks so much....
|
|
|
|
|
- Override CStatic to give you an MFC class that subclasses the picture box.
- Add an OnPaint handler to that new class.
- In the OnPaint handler, get a DC with BeginPaint
- Use MoveTo[^] and LineTo[^] to draw a line
- Add a class variable (of the type you created in step 1) for the picture box in your parent window
drawline on picture box - DONE!
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Can you pls help me with the sample code of converting Byte array to variant and vice versa
Thanks
|
|
|
|
|
Create a SAFEARRAY[^] of VT_UI1 (a VT_UI1 is equivalent to a BYTE) and encapsulate it in a VARIANT[^] with a type of VT_UI1|VT_ARRAY.
There's a sample of that in this page[^]. Search for VT_UI1 in that page to find the code!
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thanks a lot, it was very helpful
|
|
|
|
|
We are looking to add customized toolbars (and commands) to our application.
We do not necessarily need something as extensive as what is done in Visual Studio (or MS Word).
Are there easy solutions to have those kind of features in a MFC application ?
I know there's a basic support in MFC (CToolBarCtrl::Customize) but from what I see when trying to use it is that
it does not really work well.
Thanks
Max
This signature was proudly tested on animals.
|
|
|
|
|
Hi,
I did a lot of Work With Device Contexts and thought I would have to abondon that knoweledge when I used Rich edit
Then I came across ITextServices Which has a Object ITextHost with TxGetDC member
The problem ???
The Code I wrote to implement Rich Edit was in C
Is there some paragma that I can use to have piece of code compiled as C++
Or do I have re-compile the whole program as a .cpp extension to use the ITextHost Interface ??
thankx
|
|
|
|
|
Tell the compiler to compile as C++, either using project properties (for a Visual Studio project) or with the /TP option (on the command line) - that is what altering the VS project option adds in.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I have project properties to compile as C++
I got the following compile errors including textserv.h
dont know if its becuase I have a .c extension
thankx again
Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\Include\textserv.h(152) : error C2061: syntax error : identifier 'ITextServices'
1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\Include\textserv.h(152) : error C2059: syntax error : ';'
1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\Include\textserv.h(152) : error C2059: syntax error : ':'
1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\Include\textserv.h(271) : error C2061: syntax error : identifier 'ITextHost'
1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\Include\textserv.h(271) : error C2059: syntax error : ';'
1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\Include\textserv.h(271) : error C2059: syntax error : ':'
1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\Include\textserv.h(411) : error C2143: syntax error : missing ')' before '*'
1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\Include\textserv.h(411) : error C2143: syntax error : missing '{' before '*'
1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\Include\textserv.h(412) : error C2143: syntax error : missing ';' before '*'
1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\Include\textserv.h(413) : error C2143: syntax error : missing ';' before '*'
1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\Include\textserv.h(413) : error C2059: syntax error : ')'
1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\Include\textserv.h(416) : error C2143: syntax error : missing ')' before '*'
1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\Include\textserv.h(416) : error C2143: syntax error : missing '{' before '*'
1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\Include\textserv.h(417) : error C2143: syntax error : missing ';' before '*'
1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\Include\textserv.h(418) : error C2143: syntax error : missing ';' before '*'
1>C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\Include\textserv.h(418) : error C2059: syntax error : ')'
1>.\HERCCMD.C(562) : error C2065: 'ITextServices' : undeclared identifier
|
|
|
|
|
Sorry about that .....
I got other compile errors but I think I am invoking the C++ compiler
|
|
|
|
|
Hello,
First off, If this question has been answered could you direct me to the correct place. I've carried out a search but had little luck.
I've got a basic drawing program written in C++(Win32 API) which allows me to draw rectangles (using GDI functions) on the screen. I click two points on the window and a rectangle appears. When I minimize the window and restore it again, as expected the rectangle is gone.
Is there a neat solution which keeps the rectangle on screen? The only why I can see is to save the data points and call them when a WM_PAINT message is requested. To me, this method seems like it can get pretty messy, but then again I am a newbie to programming.
Thanks in advance
|
|
|
|