❔ crashing

Any idea how to prevent this code from crashing unity?
    SerialPort sp = new SerialPort("COM3", 9600);
sp.Open();

    While true()
    {
        if (sp.IsOpen)
        {
            try
            {
                serialEvent(sp);
            }
            catch (Exception)
            {
                throw;
            }
        }

    }

    void serialEvent(SerialPort myPort)
    {
        string myString = myPort.ReadLine();
        if (myString != null)
        {
                Debug.Log("Read " + myString);
        }
    }
Was this page helpful?