Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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

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).

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.

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'.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top