ogrisel: LGTM, can you please add a changelog entry and merge?
diff --git a/CHANGES.rst b/CHANGES.rst
index e08fc89..66531c1 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -4,6 +4,11 @@ Latest changes
 Release 0.9.4
 -------------
 
+Loïc Estève
+
+    FIX for raising non inheritable exceptions in a Parallel call. See
+    https://github.com/joblib/joblib/issues/269 for more details.
+
 Alexandre Abadie
 
     FIX joblib.hash error with mixed types sets and dicts containing mixed
diff --git a/joblib/my_exceptions.py b/joblib/my_exceptions.py
index 500fcd7..9d26cb5 100644
--- a/joblib/my_exceptions.py
+++ b/joblib/my_exceptions.py
@@ -64,14 +64,20 @@ def _mk_exception(exception, name=None):
         this_exception = _exception_mapping[this_name]
     else:
         if exception is Exception:
-            # We cannot create a subclass: we are already a trivial
-            # subclass
+            # JoblibException is already a subclass of Exception. No
+            # need to use multiple inheritance
             return JoblibException, this_name
-        elif issubclass(exception, JoblibException):
-            return JoblibException, JoblibException.__name__
-        this_exception = type(
-            this_name, (JoblibException, exception), {})
-        _exception_mapping[this_name] = this_exception
+        try:
+            this_exception = type(
+                this_name, (JoblibException, exception), {})
+            _exception_mapping[this_name] = this_exception
+        except TypeError:
+            # This happens if "Cannot create a consistent method
+            # resolution order", e.g. because 'exception' is a
+            # subclass of JoblibException or 'exception' is not an
+            # acceptable base class
+            this_exception = JoblibException
+
     return this_exception, this_name
 
 

Error propagating exceptions on-non subclassable types
I was using joblib to run 8 optimizations using nlopt in parallel, and got this error:

```
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-138-0fe3676d9e18> in <module>()
     31     for i in range(iterations):
     32         pool = Parallel(n_jobs=max_jobs, verbose=5)
---> 33         out = pool(delayed(nlopt_optimization)(job_id) for job_id in range(max_jobs))
     34         solutions.extend(out)
     35 

/home/federico/anaconda/lib/python2.7/site-packages/joblib/parallel.pyc in __call__(self, iterable)
    658                 # consumption.
    659                 self._iterating = False
--> 660             self.retrieve()
    661             # Make sure that we get a last message telling us we are done
    662             elapsed_time = time.time() - self._start_time

/home/federico/anaconda/lib/python2.7/site-packages/joblib/parallel.pyc in retrieve(self)
    540                             )
    541                         # Convert this to a JoblibException
--> 542                         exception_type = _mk_exception(exception.etype)[0]
    543                         raise exception_type(report)
    544                     raise exception

/home/federico/anaconda/lib/python2.7/site-packages/joblib/my_exceptions.pyc in _mk_exception(exception, name)
     67         this_exception = type(this_name, (exception, JoblibException),
     68                     dict(__repr__=JoblibException.__repr__,
---> 69                         __str__=JoblibException.__str__),
     70                     )
     71         _exception_mapping[this_name] = this_exception

TypeError: type 'nlopt.ForcedStop' is not an acceptable base type
```

My understanding is because a bunch of nlopt types are actually all generated using SWIG, and cannot be naturally inherited.  Should there be a check before joblib tries creating a nice custom exception that the type can indeed be inherited from?
diff --git a/joblib/test/test_my_exceptions.py b/joblib/test/test_my_exceptions.py
index 7c396ca..b283434 100644
--- a/joblib/test/test_my_exceptions.py
+++ b/joblib/test/test_my_exceptions.py
@@ -42,6 +42,16 @@ def test_inheritance_special_cases():
         assert_true(my_exceptions._mk_exception(exception)[0] is
                     my_exceptions.JoblibException)
 
+    # Non-inheritable exception classes should be mapped to
+    # JoblibException by _mk_exception. That can happen with classes
+    # generated with SWIG. See
+    # https://github.com/joblib/joblib/issues/269 for a concrete
+    # example.
+    non_inheritable_classes = [type(lambda: None), bool]
+    for exception in non_inheritable_classes:
+        assert_true(my_exceptions._mk_exception(exception)[0] is
+                    my_exceptions.JoblibException)
+
 
 def test__mk_exception():
     # Check that _mk_exception works on a bunch of different exceptions

pip install -e .
parse_log_pytest
pytest
nose coverage pytest
3.5
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
attrs @ file:///opt/conda/conda-bld/attrs_1642510447205/work
certifi==2021.5.30
coverage==6.2
importlib-metadata @ file:///tmp/build/80754af9/importlib-metadata_1631916693255/work
iniconfig @ file:///home/linux1/recipes/ci/iniconfig_1610983019677/work
-e git+https://github.com/joblib/joblib.git@4a9c63d7984bc5e630722b8bf72c0c720a6bd5c0#egg=joblib
more-itertools @ file:///tmp/build/80754af9/more-itertools_1637733554872/work
nose==1.3.7
packaging @ file:///tmp/build/80754af9/packaging_1637314298585/work
pluggy @ file:///tmp/build/80754af9/pluggy_1615976315926/work
py @ file:///opt/conda/conda-bld/py_1644396412707/work
pyparsing @ file:///tmp/build/80754af9/pyparsing_1635766073266/work
pytest==6.2.4
toml @ file:///tmp/build/80754af9/toml_1616166611790/work
typing_extensions @ file:///opt/conda/conda-bld/typing_extensions_1647553014482/work
zipp @ file:///tmp/build/80754af9/zipp_1633618647012/work

name: joblib
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - attrs=21.4.0=pyhd3eb1b0_0
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - importlib-metadata=4.8.1=py36h06a4308_0
  - importlib_metadata=4.8.1=hd3eb1b0_0
  - iniconfig=1.1.1=pyhd3eb1b0_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - more-itertools=8.12.0=pyhd3eb1b0_0
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - packaging=21.3=pyhd3eb1b0_0
  - pip=21.2.2=py36h06a4308_0
  - pluggy=0.13.1=py36h06a4308_0
  - py=1.11.0=pyhd3eb1b0_0
  - pyparsing=3.0.4=pyhd3eb1b0_0
  - pytest=6.2.4=py36h06a4308_2
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - toml=0.10.2=pyhd3eb1b0_0
  - typing_extensions=4.1.1=pyh06a4308_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zipp=3.6.0=pyhd3eb1b0_0
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - coverage==6.2
      - nose==1.3.7
prefix: /opt/conda/envs/joblib

joblib/test/test_my_exceptions.py::test_inheritance_special_cases
joblib/test/test_my_exceptions.py::test_inheritance joblib/test/test_my_exceptions.py::test__mk_exception
CHANGES.rst joblib/my_exceptions.py
CHANGES.rst joblib/my_exceptions.py