ããã¥ã¡ã³ãã«ãªãUnityç¬èªã®Exception
Unityã«ã¯ããã¥ã¡ã³ãã«ã¯ãªãExeptionãå¤æ°ããã¾ãã
ããã¥ã¡ã³ãåããã¦ããã®ã¯PlayerPrefsExceptionã ããªãã§ãããã
UnassignedReferenceException
主ã«å¤æ°ã«å¤ãã»ããããã¦ããªãå ´åã«ä½¿ç¨ãããException
publicã§Inspectorä¸ã«ããããã£ã表示ããã¾ã¾ä½ãã»ããããã«ããã¨çºç
public GameObject obj; //ä¸èº«ã¯ç©º void Start () { Instantiate (obj); }
MissingComponentException
ã³ã³ãã¼ãã³ããåå¾ããGetComponentç³»ã§ã³ã³ãã¼ãã³ããåå¾ã§ããªãã£ãå ´åã«ä½¿ç¨ããException
void Start () { //Hogeã¨ããã³ã³ãã¼ãã³ãã¯ãã®ã²ã¼ã ãªãã¸ã§ã¯ãã«ã¢ã¿ããããã¦ããªã if (GetComponent<Hoge> () == null) throw new MissingComponentException (); }
MissingReferenceException
åç §å ãè¦ã¤ãããªãå ´åã«ä½¿ç¨ãããException
private GameObject obj; IEnumerator Start () { obj = new GameObject ("hoge"); Destroy (obj); //åé¤ yield return new WaitForEndOfFrame(); //åé¤ãããã¾ã§å¾ 㤠Debug.Log (obj.transform); //åé¤ãããobjã®transformãåå¾ãã }
ExitGUIException
GUIã表示åºæ¥ãªããã¾ãã¯è¡¨ç¤ºããããªãå ´åã«ä½¿ç¨ãããException
é常ãã®Exceptionã¯ãã°ã«è¡¨ç¤ºããã¾ãããEditorScriptã§ã¯è¡¨ç¤ºãããå ´åãããã¾ã
void OnGUI () { //try-catchããã¨ãããããã try { GUIUtility.ExitGUI (); //ExitGUIExceptionãã¹ãã¼ããã ã } catch (ExitGUIException e) { Debug.Log (e); } GUILayout.Box ("hoge");ã//try-catchãå¤ãã¨è¡¨ç¤ºãããªã }
UnityException
Unityã«é¢é£ãããªãã§ãããããªException
大æµã¯ã¡ãã»ã¼ã¸ãè¦ã¦å¤æãã