I’m learning about exception handling and am looking for advice on the best way to handle Resources.Load failing. The way I see it theres two ways to check, a Try Catch, or an if(null). The way I understand it, theres two options
// #1 ----- Try/catch -----------
try{
picture = Resources.Load<Texture2D>("MonkAssets/emm-logo-2014");
}
catch(NullReferenceException e){
Debug.LogError("Asset not loaded" + e.ToString());
}
catch(Exception e){
Debug.Log(e.ToString());
}
// #2 ------if/then------------
picture = Resources.Load<Texture2D>("MonkAssets/emm-logo-2014");
if(picture != null){
// Do stuff
}else{
Debug.LogError("Asset not loaded");
}
I understand that the if/then is faster and has less overhead, and that generally Try/Catch should be used sparingly and specifically, my question is specifically in this case, is Resources.Load risky enough to warrant using the try/catch? Which is better practice and why?
Thanks in advance.
Dylan