Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to import UNO exceptions?

I'm working on a Python application that uses a running LO instance. I'd like to know how to import the LO specific exceptions that may occur when running my program. Background below, but the prompting motivation for this question is that I want to catch the specific LO error "NoConnectException". How do I import this error from UNO? No iteration of "from uno import ..." I've tried seems to work.

Background:

When a program exception occurs that is actionable, the "Pythonic way" is to be as specific about handling it as possible. For instance, if I have a list of 5 elements, and I try to select the 6th one, that is more specifically an IndexError, rather than just a general Exception. Thus, instead of code like this:

my_list = [1, 2, 3, 4, 5]  # indexed from 0 through 4
i = 5
try:
  num = my_list[i]
except Exception, e:
  print("You insensitive clod!  {} is not a valid index!").format( i )

it is better to use the specific error you intend to handle, thus preventing the masking of an actual error:

my_list = [1, 2, 3, 4, 5]  # indexed from 0 through 4
i = 5
try:
  num = my_list[5]
except IndexError, e:
  print("You insensitive clod!  {} is not a valid index!").format( i )

How do I import the LO specific errors that can occur? I've tried a number of iterations, but I don't know where to look these up and api.libreoffice.org is not (currently) proving much help to me.

click to hide/show revision 2
Python 3 syntax for LO4+ (not that it matters for this question...)

How to import UNO exceptions?

I'm working on a Python application that uses a running LO instance. I'd like to know how to import the LO specific exceptions that may occur when running my program. Background below, but the prompting motivation for this question is that I want to catch the specific LO error "NoConnectException". How do I import this error from UNO? No iteration of "from uno import ..." I've tried seems to work.

Background:

When a program exception occurs that is actionable, the "Pythonic way" is to be as specific about handling it as possible. For instance, if I have a list of 5 elements, and I try to select the 6th one, that is more specifically an IndexError, rather than just a general Exception. Thus, instead of code like this:

my_list = [1, 2, 3, 4, 5]  # indexed from 0 through 4
i = 5
try:
  num = my_list[i]
except Exception, e:
Exception( e ):
  print("You insensitive clod!  {} is not a valid index!").format( i )

it is better to use the specific error you intend to handle, thus preventing the masking of an actual error:

my_list = [1, 2, 3, 4, 5]  # indexed from 0 through 4
i = 5
try:
  num = my_list[5]
except IndexError, e:
IndexError( e ):
  print("You insensitive clod!  {} is not a valid index!").format( i )

How do I import the LO specific errors that can occur? I've tried a number of iterations, but I don't know where to look these up and api.libreoffice.org is not (currently) proving much help to me.

click to hide/show revision 3
Python3, ... third times the charm. Sigh. Hooray for end-of-the-day.

How to import UNO exceptions?

I'm working on a Python application that uses a running LO instance. I'd like to know how to import the LO specific exceptions that may occur when running my program. Background below, but the prompting motivation for this question is that I want to catch the specific LO error "NoConnectException". How do I import this error from UNO? No iteration of "from uno import ..." I've tried seems to work.

Background:

When a program exception occurs that is actionable, the "Pythonic way" is to be as specific about handling it as possible. For instance, if I have a list of 5 elements, and I try to select the 6th one, that is more specifically an IndexError, rather than just a general Exception. Thus, instead of code like this:

my_list = [1, 2, 3, 4, 5]  # indexed from 0 through 4
i = 5
try:
  num = my_list[i]
except Exception( e ):
Exception as e:
  print("You insensitive clod!  {} is not a valid index!").format( i )

it is better to use the specific error you intend to handle, thus preventing the masking of an actual error:

my_list = [1, 2, 3, 4, 5]  # indexed from 0 through 4
i = 5
try:
  num = my_list[5]
except IndexError( e ):
IndexError as e:
  print("You insensitive clod!  {} is not a valid index!").format( i )

How do I import the LO specific errors that can occur? I've tried a number of iterations, but I don't know where to look these up and api.libreoffice.org is not (currently) proving much help to me.