コード例 #1
0
        private void ThrowException()
        {
            if (m_Dll == null)
            {
                return;
            }

            SysErrNo managedErrNo;
            string   sysDescription;

            try {
                // These methods were first added in libnserial 1.1
                managedErrNo   = m_Dll.netfx_errno(m_Dll.errno);
                sysDescription = m_Dll.netfx_errstring(m_Dll.errno);
            } catch (System.EntryPointNotFoundException) {
#if NETSTANDARD15
                ThrowExceptionNetStandard();
#else
                ThrowExceptionMono();
#endif
                throw;
            }
            string libDescription = m_Dll.serial_error(m_Handle);

            string description = string.Format("{0} ({1}; {2})",
                                               libDescription, m_Dll.errno, sysDescription);

            switch (managedErrNo)
            {
            case SysErrNo.NETFX_OK:
            case SysErrNo.NETFX_EINTR:
            case SysErrNo.NETFX_EAGAIN:
            case SysErrNo.NETFX_EWOULDBLOCK:
                // We throw here in any case, as the methods that call ThrowException don't
                // expect it to return. This would mean something that needs to be debugged
                // and fixed (probably in the C Interop Code).
                throw new InternalApplicationException(description);

            case SysErrNo.NETFX_EINVAL:
                throw new ArgumentException(description);

            case SysErrNo.NETFX_EACCES:
                throw new UnauthorizedAccessException(description);

            case SysErrNo.NETFX_ENOMEM:
                throw new OutOfMemoryException(description);

            case SysErrNo.NETFX_EBADF:
                throw new InvalidOperationException(description);

            case SysErrNo.NETFX_ENOSYS:
                throw new PlatformNotSupportedException(description);

            case SysErrNo.NETFX_EIO:
                throw new IOException(description);

            default:
                throw new InvalidOperationException(description);
            }
        }
コード例 #2
0
ファイル: UnixNativeSerial.cs プロジェクト: TiboVDS/Horeka
        public UnixNativeSerial()
        {
            m_Dll = new SerialUnix();
            m_Handle = m_Dll.serial_init();
            if (m_Handle.IsInvalid) {
                throw new PlatformNotSupportedException("Can't initialise platform library");
            }
            m_HandlePtr = m_Handle.DangerousGetHandle();

#if NETSTANDARD15
            // On NetStandard 1.5, we must have proper exception handling
            try {
                // These methods were first added in libnserial 1.1
                m_Dll.netfx_errno(0);
            } catch (System.EntryPointNotFoundException) {
                throw new PlatformNotSupportedException("Must have libnserial 1.1.0 or later on .NET Standard 1.5");
            }
#endif
        }