0

How to return Error message that output by SerialException? In here i try to open port in port that already open. I want to get error that occurs. In the case SerialException will return Access is denied

could not open port 'COM38': PermissionError(13, 'Access is denied.', None, 5)

import serial
from serial import SerialException

def open:
  try:
    serial.Serial('COM38', 9600)

    return True
  except SerialException:
    #How to return error message that serial exception occurs?
    return Raise

print(open())
IOSBET
  • 61
  • 1
  • 1
  • 6

1 Answers1

0

Hope help.

import serial
from serial import SerialException

def open:
  try:
    serial.Serial('COM38', 9600)

    return True
  except PermissionError as e:
      message = str(e)
      raise SerialException(message)
  except SerialException as ex:
      print(ex)

print(open())
Dmitry Leiko
  • 3,970
  • 3
  • 25
  • 42