![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Programming Guru
![]() Join Date: Apr 2005
Posts: 1,799
Rep Power: 5
![]() |
Re: Exception handling: point is...?
|
|
|
|
|
|
#12 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,198
Rep Power: 5
![]() |
Re: Exception handling: point is...?
While I have the capability to do so, I have never incapacitated anyone's ability to learn, and hopefully will never have to.
|
|
|
|
|
|
#13 |
|
Hobbyist
Join Date: Sep 2005
Posts: 259
Rep Power: 3
![]() |
Re: Exception handling: point is...?
Channel 9 did an interview with Ale Contenti on exception handling. People here might find it interesting.
Understanding Exceptions and When/How to Handle Them: http://channel9.msdn.com/Showpost.aspx?postid=343189 I was surprised to learn about the amount of bookkeeping that goes on under the covers when using exceptions. |
|
|
|
|
|
#14 | |
|
hi: for(;;) goto hi;
|
Re: Exception handling: point is...?
Quote:
__________________
How do you play Religious Roulette? Stand around in a circle and blaspheme till someone gets struck by lightning. |
|
|
|
|
|
|
#15 |
|
Not a user?
Join Date: Sep 2007
Posts: 245
Rep Power: 1
![]() |
Re: Exception handling: point is...?
From what I know about error handling (which is pretty slim) it could be more robust. Let me use an example. If you're capturing keyboard input in your program, you poll for whatever keystrokes and if found, you mark it as handled, otherwise it goes on to the OS to be handled. Error handling, from my recollection, doesn't have this function. Why?
The error handling mechanism automatically handles every error, even if it doesn't? That seems broken. |
|
|
|
|
|
#16 |
|
hi: for(;;) goto hi;
|
Re: Exception handling: point is...?
How's this for a first attempt?
c++ Syntax (Toggle Plain Text)
__________________
How do you play Religious Roulette? Stand around in a circle and blaspheme till someone gets struck by lightning. |
|
|
|
|
|
#17 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,198
Rep Power: 5
![]() |
Re: Exception handling: point is...?
That code would be thrown out in any serious code review, and the author sacked on the spot.
There is no practical need to throw/catch an exception if a function that that detects an error can recover from it. It would be simpler to just recover on the spot ..... and return false. The code is simpler, easier to understand, and probably (depending on how exception handling is implemented by your compiler) more efficient. 0,1, and negative values are, by definition, non-prime (yes, your algorithm is incorrect as it returns true for 1) so the error recovery is trivial. I won't even address that fact that, efficiency wise, the loop is .... bleh! |
|
|
|
|
|
#18 |
|
Programming Guru
![]() Join Date: Apr 2005
Posts: 1,799
Rep Power: 5
![]() |
Re: Exception handling: point is...?
Yikes! Your function says 1 is a prime number, and 2 is composite!
|
|
|
|
|
|
#19 | ||
|
hi: for(;;) goto hi;
|
Re: Exception handling: point is...?
Factors of 2: 1, 2, ?
As for grumpy Quote:
Quote:
Regardless, c++ Syntax (Toggle Plain Text)
__________________
How do you play Religious Roulette? Stand around in a circle and blaspheme till someone gets struck by lightning. |
||
|
|
|
|
|
#20 |
|
Programming Guru
![]() Join Date: Apr 2005
Posts: 1,799
Rep Power: 5
![]() |
Re: Exception handling: point is...?
I can't tell if you were agreeing or disagreeing with me, but either way, your new code handles
n=2 properly now. Your old code returned false when n % 2 == 0. That was incorrect, since 2 is a prime number. Anyways, you have it now. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Exception Handling and Events | InfoGeek | C# | 3 | Jan 9th, 2008 1:10 AM |
| exception handling class | rwm | C++ | 5 | Apr 10th, 2007 5:17 AM |
| exception handling | l2u | C++ | 2 | Mar 3rd, 2007 5:47 PM |
| Exception Handling with Threads | Harakim | Software Design and Algorithms | 13 | Aug 8th, 2006 6:00 AM |
| exception handling | chrome_knob | Java | 2 | May 19th, 2005 5:45 PM |