- Home /
Catch Exception from a failed Unity Command
What I am trying to do :
Using following few lines of code I am trying to create a Prefab in a directory. Using try-catch statement, I want to create prefab under "Assets" folder if provided directory does not exist.
What is not working:
When PrefabUtility.CreatePrefab() command fails when provided directory does not exist, it should throw an exception which eventually should execute catch() code i.e. create prefab under "Assets" folder. But it is not doing so.
Code :
string PrefabDir = "Assets/_prefabs";
try
{
PrefabUtility.CreatePrefab (PrefabDir + modelGameObj.name + ".prefab", modelGameObj);
}
catch(Exception e)
{
Debug.Log (e);
PrefabUtility.CreatePrefab ("Assets/" + modelGameObj.name + ".prefab", modelGameObj);
}
What I also tried :
I also tried catch UnityException, which doesn't seem to be working as well. [ catch( UnityException e) ]
I can definitely check if directory exist using Directory.Exists(PrefabDir) but I want to understand why it is not catching the exception.
Thanks
Your answer
Follow this Question
Related Questions
Try/Catch block stops exception from happening 0 Answers
Stop Game on Exception 4 Answers
C# try catch block doesn't work for iOS? 2 Answers
Try Catch not working with VideoPlayer 2 Answers