views:

1558

answers:

5

I know that this probably doesn't really matter, but I would like to know what is correct.

If a piece of code contains some version of throw new SomeKindOfException(). Do we say that this piece of code can potentially raise an exception? Or throw an exception?

The keyword is throw, so I am kind of leaning towards that, but to raise an exception is also used a lot...

Do they have some sort of different meaning? Does one of them sort of implicate a difference over the other? Or is it just two words meaning exactly the same thing?

+20  A: 

In C# terminology, raising is used in the context of events and throwing is used in the context of exceptions.

Personally, I think throw/catch combination is more beautiful than raise/catch.

Mehrdad Afshari
Ah, of course, I totally agree. Makes total sense now! Thank you for clearing that up :)
Svish
C# also uses "lift", to mean "provide a nullable version of an operator on non-nullable types", and "hoist" to mean "turn a local variable into a field of a closure class". So in C# you can raise, hoist or lift things, and they all mean something different.
Eric Lippert
+3  A: 

I can't speak for C#, but in C++ "throw" was chosen because "raise" was already taken as a standard function name.

anon
+1  A: 

I think while throw is the better one, the two terms are interchangeable. Very useful if you have to use it twice in some text so that you avoid repeating the same word. But that's stylistics which is not necessary for technical writing (but still a nice thing to have).

DrJokepu
A: 

Either throw or raise seems fine, they mean the same to me. I wouldn't write it, but when I'm talking, I usually say 'chuck an exception'.

For events I'd use either 'fire an event' or 'raise an event'.

Scott Langham
"Fire" is of course in common usage for events. When coming up with terminology guidelines, the team doing so thought that "fire" seemed unnecessarily belicose, so they suggested eschewing "fire" in favour of "raise". My personal opinion is that this is a bit silly, but "raise" is fine and we might as well standardize on one or the other.
Eric Lippert
A: 

The terminology of the various languages favors 'throw'. And I agree that 'throw' makes a lot more sense considering this is the keyword used and the compiler/language documentation always refers to exception being 'thrown'.

However, in the belly of the behemoth exceptions are actually Raised, not thrown. If you find yourself deep enough in debugger staring at an EXCEPTION_RECORD then you talk in the terminology of SEH, in which the particular class of compiler/language exceptions (eh, clr, vcpp) is just one of the many flavors exceptions come as. I guess the original conditions for which exceptions where raised for, like page faults and stack overflows, were conditions 'noticed' by the kernel that was 'informing' the user mode of the condition and not exception the user code was 'throwing' onto himself, so the term makes more sense in that context.

Remus Rusanu