Ask Your Question
0

How to import UNO exceptions? [closed]

asked 2013-02-17 23:50:14 +0200

hunteke gravatar image

updated 2013-02-18 00:22:23 +0200

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 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 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.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2015-10-22 02:37:27.001008

1 Answer

Sort by » oldest newest most voted
0

answered 2013-02-17 23:56:43 +0200

hunteke gravatar image

Sigh, that's embarrassing. Not 5 minutes after posting this, I ran across the answer. (Why couldn't I have found this before I posted. Oh well.)

The answer is to first import uno, and then import from com:

import uno
from com.sun.star.connection import NoConnectException
edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-02-17 23:50:14 +0200

Seen: 240 times

Last updated: Feb 18 '13