Skip to content

LJMError should be moved into its own exception module #9

@jbiams77

Description

@jbiams77

by defining the same LJMError class in the module where it is used, there exists a chicken/egg problem where the LJMError cannot be used to catch exception when importing LJM library.

For example:

try:
    from labjack import ljm
except labjack.ljm.ljm.LJMError as exception:
    raise LabjackLibraryNotInstalled from exception

cannot work because the LJMError is defined in the same module. A better practice is to seperate the exception class into it's own module that only depends on Python standard library, this ensures Labjack package exceptions can be used for module imports that wrap library code, just as labjack-ljm-python wraps the LJM library that is required to be installed.

Another issue is that the _loadLibrary() function catches the LJMError exception, prints the error, then returns None. Why? If the python package doesn't work without the LJM library, then it shouldn't handle the exception, it should just raise it and let the calling module handle the exception.

Please remove from _loadLibrary():

    except LJMError:
        ljme = sys.exc_info()[1]
        print(str(type(ljme)) + ": " + str(ljme))
        return None

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions