def get_exdesc():
<EOL>fname = inspect.getframeinfo(sys._getframe(<NUM_LIT:1>))[<NUM_LIT:2>]<EOL>count = <NUM_LIT:0><EOL>fobj = None<EOL>while not (fobj and hasattr(fobj, "<STR_LIT>")):<EOL><INDENT>count = count + <NUM_LIT:1><EOL>try:<EOL><INDENT>sitem = sys._getframe(count)<EOL><DEDENT>except ValueError:<EOL><INDENT>raise RuntimeError(<EOL>"<STR_LIT>".format(fname)<EOL>)<EOL><DEDENT>fobj = (<EOL>sitem.f_locals[fname]<EOL>if fname in sitem.f_locals<EOL>else (sitem.f_globals[fname] if fname in sitem.f_globals else None)<EOL>)<EOL><DEDENT>exdesc = getattr(fobj, "<STR_LIT>")<EOL>return exdesc if len(exdesc) > <NUM_LIT:1> else exdesc[next(iter(exdesc))]<EOL>
Retrieve contract exception(s) message(s).

If the custom contract is specified with only one exception the return
value is the message associated with that exception; if the custom contract
is specified with several exceptions, the return value is a dictionary
whose keys are the exception names and whose values are the exception
messages.

:raises: RuntimeError (Function object could not be found for
 function *[function_name]*)
:rtype: string or dictionary

For example:

.. =[=cog
.. import docs.support.incfile
.. docs.support.incfile.incfile('pcontracts_example_2.py', cog.out)
.. =]=
.. code-block:: python

    # pcontracts_example_2.py
    import pexdoc.pcontracts

    @pexdoc.pcontracts.new_contract('Only one exception')
    def custom_contract_a(name):
        msg = pexdoc.pcontracts.get_exdesc()
        if not name:
            raise ValueError(msg)

    @pexdoc.pcontracts.new_contract(ex1='Empty name', ex2='Invalid name')
    def custom_contract_b(name):
        msg = pexdoc.pcontracts.get_exdesc()
        if not name:
            raise ValueError(msg['ex1'])
        elif name.find('[') != -1:
            raise ValueError(msg['ex2'])

.. =[=end=]=


In :code:`custom_contract1()` the variable :code:`msg` contains the string
``'Only one exception'``, in :code:`custom_contract2()` the variable
:code:`msg` contains the dictionary
:code:`{'ex1':'Empty name', 'ex2':'Invalid name'}`.