|
IMO, it's excessive; especially if you're talking about "catch(...)". unless every function is calling off to code you have no control over that has a high likelyhood of doing something stupid, you should be able to handle most possible error conditions on your own: test that pointer before using it, check your array bounds, etc.. at the very least, checking for possible error conditions will let you handle some situations gracefully. with catch(...), the error has already happened, and you don't really know what caused it, or what the state of the system is.
on the other hand, if your code actually uses specific exception objects as a form of code flow (ie. as C++ friendly goto's), then you might see a lot of try/catch blocks. but, even then, you wouldn't likely have them on every function.
-c
Though the cough, hough and hiccough so unsought would plough me through,
enough that I o'er life's dark lough my thorough course pursue.
--Stuart Kidd
|
|
|
|
|
Chris Losinger wrote:
IMO, it's excessive;
I would agree. However the reason I want to use try/catch is very un-conventional.
I always thought that under most circumstances you could get away with traditional if/then error handling techniques, instead of the more expensive try/catch.
Like u said so long as you initialize/check your pointers check the bounds of arrays etc...why bother using try/catch.
I look at try/catch as an alpha release technique to track down unrecognized bugs and fix them up with the faster more efficient if statements.
Anyways...thanx for the input
Cheers!
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
Hockey wrote:
I always thought that under most circumstances you could get away with traditional if/then error handling techniques, instead of the more expensive try/catch.
How much more expensive is try/catch when compared to dozens of if statements?
How much more readable is one exception handler than dozens of if statements?
Tomasz Sowinski -- http://www.shooltz.com
"Yields falsehood when preceded by its quotation" yields falsehood when preceded by its quotation.
|
|
|
|
|
Tomasz Sowinski wrote:
How much more expensive is try/catch when compared to dozens of if statements?
I would think quite a few more clocks are expended using try and catch. I suppose you could profile it and find out.
Tomasz Sowinski wrote:
How much more readable is one exception handler than dozens of if statements?
This is true, but it's harder or near impossible to determine what went wrong given the context of the situation. Where as i absolutely know what went wrong i use if's.
cheers
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
Hockey wrote:
I would think quite a few more clocks are expended using try and catch. I suppose you could profile it and find out.
Sure. The real question is: do you need these clock ticks. 'Premature optimization is the root of programming evil' - do you know who said this?
Hockey wrote:
it's harder or near impossible to determine what went wrong given the context of the situation.
If you need different actions in different context, write different catch handlers.
Anyway, I'm not going to preach and convert you to try/catch. If you want to live in early 90s, it's OK with me.
Tomasz Sowinski -- http://www.shooltz.com
"Yields falsehood when preceded by its quotation" yields falsehood when preceded by its quotation.
|
|
|
|
|
I've always been facinated with code optimizations...I suppose it has a lot to do with the fact that I haven't had a new computer in like 5-8 years...
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
Hockey wrote:
I've always been facinated with code optimizations
Nothing wrong with that... as long as fascination doesn't turn into obsession. If you want to optimize, profile first. I don't believe you'll find that using exceptions will slow your code down.
BTW: are you aware that calling new/malloc and delete/free is quite expensive?
Tomasz Sowinski -- http://www.shooltz.com
"Yields falsehood when preceded by its quotation" yields falsehood when preceded by its quotation.
|
|
|
|
|
Perhaps a slight obsession...
I seem to wanna go back in time rather than move forward with technology...honestly i'd rather code in assembler than anything...just cuz you have total control of everything. Sounds ridiculous, but i've never claimed to be the most productive programmer.
Actually I really enjoy OOP...the whole object concept is really cool too...i've always hated hi level procedural langs...like QBasic or Pascal...tho
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
Hi
I have a dialog based application that uses many popup windows to display data. I changed the icon for these popups and it shows in the popup window and the task bar.
My prob is the new icon will not display (on the 'switch-to-program popup' window) when I press Atl-tab to swap between windows. What do I need to do for it to show up.
<br />
CMyWnd * mywnd = new CMyWnd (this);<br />
mywnd->Create(IDD_MYICON,GetDesktopWindow());<br />
HICON icon = AfxGetApp()->LoadIcon(IDI_MYICON);<br />
mywnd->SetIcon(icon);<br />
thanks
---
|
|
|
|
|
You need to change the large (32x32) icon also.
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Hello all,
I am currently trying to develop an application using Visual C++. This application uses two different existing libraries, one of which (DirectShow) is compiled using the __stdcall naming convention, the other and SGI library is compiled using the __cdecl naming convention. The problem is that I need to use both these libraries in developing my filter, when I compile using __stdcall I get link errors in resolving the SGI library methods. When I compile using __cdecl I get errors in resolving the DirectShow methods.
Both libraries are C++ libraries, neither library is small enough to directly specify the function/class names, they require inclusion of numerous header files. The SGI library header are improperly declared (not specified as __cdecl in the headers).
Does anybody have any suggestions??
|
|
|
|
|
There's an easy way to force functions to be __cdecl. Just do this
extern "C" {
#include <sgi_headers.h>
}
Then just compile using __stdcall, and it should work.
|
|
|
|
|
Thanks for replying, I already tried that and it gives me loads of errors (102 of them) such as
C:\PROGRAM FILES\SILICON GRAPHICS\SDK\INCLUDE\ocs/ox/corba.h(699) : error C2733: second C linkage of overloaded function '_type_code' not allowed
C:\PROGRAM FILES\SILICON GRAPHICS\SDK\INCLUDE\ocs/ox/corba.h(699) : see declaration of '_type_code'
C:\PROGRAM FILES\SILICON GRAPHICS\SDK\INCLUDE\ocs/ox/corba.h(703) : error C2733: second C linkage of overloaded function '_type_code' not allowed
C:\PROGRAM FILES\SILICON GRAPHICS\SDK\INCLUDE\ocs/ox/corba.h(703) : see declaration of '_type_code'
C:\PROGRAM FILES\SILICON GRAPHICS\SDK\INCLUDE\ocs/ox/corba.h(707) : error C2733: second C linkage of overloaded function '_type_code' not allowed
C:\PROGRAM FILES\SILICON GRAPHICS\SDK\INCLUDE\ocs/ox/corba.h(707) : see declaration of '_type_code'
....
....
....
what else can I do, this is for my thesis at uni.... and the due date is approaching fast, and I cant even get it compiled!
|
|
|
|
|
'_type_code' is redefined , Use another function name!
Everyone is my teacher!
|
|
|
|
|
Hello, I was wondering what is required of a bitmap for it to displayed with a
transparent background when used as a toolbar button. I have two bitmaps, and when used in the same code, one yields transparent button backgrounds and the other doesn't. The bitmap that yields transparent backgrounds was used in a project I did three years ago, but I can't see anything special with it. Both got black background. I know the bitmap that will yield transparent background, but that is because that it was part of a larger toolbar bitmap in an unconventional size that I reduced to a size of 16*15 (using the resource editor).
I am putting the entire project on the following url if anyone wants to take a look.
http://www-und.ida.liu.se/~mikas493/code.zip
Please! This is driving me crazy!
|
|
|
|
|
CToolBarCtrl uses image lists so according to MSDN:
An image list may also include a monochrome bitmap that contains masks used to draw images transparently (icon style).
HTH
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
Hi,
I really really desperately need to learn how to get the amount the listview control has scrolled of. Like 10 pixels up or 40 pixels down... I cannot find it anywhere... Thanks
|
|
|
|
|
Just a guess
UINT nScrollPos = GetScrollPos(SB_VERT)
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
yeah, but that gives me the position instead of the amount of pixel scrolled. Even if I keep the last position and calculate it then, then how will I get the result if it it the first time I request the position and have no previous one... Okay, ,aybe I can assume it was 0... and can I assume it is position = scroll amount in pixels?
Thanks
|
|
|
|
|
If GetScrollBar () is retuning the index of the top most item in the list...multiply this number by the height of each individual item. This value I think can be retreived via CListCtrl::GetItemRect()
That calculation will return scroll position in pixels...i think...
HTH
cheers
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
I have created modal dialog and I passed pointer to my View class to it.
Now I need to get input from the dialog and update my List control in View class in real time.
Is there any way to overwrite modal stage of the view only for input a then reset it back.
|
|
|
|
|
pepevejlupek wrote:
Is there any way to overwrite modal stage of the view only for input a then reset it back.
What do you mean by that?
If you just need to get the data from the dialog and update the view class; just get the data in the part that you call the modal dialog. Then pass this data to your View class using either messaging or calling the functions of the view directly.
Mustafa Demirhan
http://www.macroangel.com
Sonork ID 100.9935:zoltrix
<nobr>They say I'm lazy but it takes all my time
|
|
|
|
|
thanks i found my problem. it had nothing to do with modal dialog.
|
|
|
|
|
Hello there,
Please introduce good book for learning VC++ .NET ...
I want to learn about .NET, writing webservers and etc by MC++ managed code ...
Regards,
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
Can't go wrong with books from MSPress. Try here[^]
Paul Lyons
Certified Code Project Lurker
|
|
|
|