Throw or Debug. LogError ?

Joined
Apr 19, 2020
Messages
7
Programming Experience
1-3
Hi, everybody.

Why and when do I use "Debug.LogError" if I can always use "throw"?

I just don't understand the logic of the choice.

I have an example of the class "SteamAPI", they are initializing and in cases of failure, "Debug.LogError.... return;" is called where the error is written, BUT why not call "throw"? The same way an error will be written to the console.

I understand that "throw" interrupts execution.
 
The throw keyword is specifically intended to throw an exception. If you want to throw an exception then use it and if you don't want to then don't use it. If they aren't using it then obviously they don't want to throw an exception. If they are using Debug.LogError then presumably they only want to log an error while debugging. Logging an error just means writing somewhere that it happened but the app carries on normally otherwise. Throwing an exception means terminating all executing methods until a handler catches it or else crashing the app. Very different behaviours.
 

Latest posts

Back
Top Bottom