4 Replies - 1017 Views - Last Post: 23 July 2015 - 04:28 AM Rate Topic: -----

#1 mfrench   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 29-June 15

C++ vs C# on exceptions

Posted 20 July 2015 - 11:40 PM

This is from Wikipedia:

"According to a 2006 comparative paper by Joseph R. Kiniry, programming
languages differ substantially in their notion of what is an exception.
According to Kiniry, the contemporary languages can be roughly divided in two groups:[7]
those languages in which exceptions 'are designed to be used as flow
control structures'; according to this paper,

Ada, C++, Java, Modula-3,
ML, OCaml, Python, and Ruby fall in this category

those languages in which exceptions "are designed to represent and handle
abnormal, unpredictable, erroneous situations"; according to the paper

these include: C#, Common Lisp, Eiffel, and Modula-2."


From the little of I know of C# and C++, and from the little I know of exceptions, they don't seem to be terribly different. C++ exceptions still deal with "abnormal, unpredictable, and erroneous situations". Can someone shed some light on this Wikipedia citation that puts C# and C++ in different categories with regard to exceptions? Thanks.

Is This A Good Question/Topic? 0
  • +

Replies To: C++ vs C# on exceptions

#2 baavgai   User is offline

  • Dreaming Coder
  • member icon


Reputation: 7482
  • View blog
  • Posts: 15,509
  • Joined: 16-October 07

Re: C++ vs C# on exceptions

Posted 21 July 2015 - 03:54 AM

I'd call BS on this.

Exceptions always "represent and handle abnormal, unpredictable, erroneous situations." Using them as flow control, in any language, is considered bad design.

Google any of the languages where it is asserted that exceptions are "designed to be used as flow control." e.g. http://www.google.co...0flow%20control

That's not to say you wont find some programmers who defend such a misguided practice. Such backward individuals are generally a fringe group to be ingnored.

Granted, there might be a language in there where an "exception as flow control" practice has become common. At which point, the concept of exception has lost meaning.
Was This Post Helpful? 1
  • +
  • -

#3 Xupicor   User is offline

  • Nasal Demon
  • member icon

Reputation: 457
  • View blog
  • Posts: 1,179
  • Joined: 31-May 11

Re: C++ vs C# on exceptions

Posted 21 July 2015 - 05:49 AM

I don't quite get it either, using exceptions as flow control is certainly possible, and is usually frowned upon*.

___
*) Well, if it's used where there are no erroneous, abnormal, unpredictable situations... It is flow control, but supposed to be used for specific tasks. ;)

This post has been edited by Xupicor: 24 July 2015 - 09:38 AM

Was This Post Helpful? 0
  • +
  • -

#4 Martyr2   User is offline

  • Programming Theoretician
  • member icon

Reputation: 5465
  • View blog
  • Posts: 14,418
  • Joined: 18-April 07

Re: C++ vs C# on exceptions

Posted 22 July 2015 - 09:38 AM

Well when you think about it, of course it is a mechanism for flow control, but that is because it is in response to "abnormal, unpredictable, erroneous situations."

I don't see how these two things really differ. The fact that, when you are in a try statement and hit an error which causes it to jump to the catch you are changing flow.

But agreed, you shouldn't be using try catching as some way to purposely change flow like some kind of if statement or whatever. Use it to catch erroneous situations. Really a discussion we shouldn't be concerning our time with in my honest opinion. Use it as it is supposed to be used and you won't have issues.

:)
Was This Post Helpful? 0
  • +
  • -

#5 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7054
  • View blog
  • Posts: 23,983
  • Joined: 05-May 12

Re: C++ vs C# on exceptions

Posted 23 July 2015 - 04:28 AM

How about using exceptions to create a do-while loop like in my posting in the Nightmare.In.Code forum?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1