Question: I have a short script in python and I need get the exception, but only a valueError not the full content. I explain with the code:

```
try:
   r = str(ML_engine.Create_ML_Alg_Python(sc, m))
   ML_engine.updateModel('success',r,m)
   return r
except Exception as inst:
   ML_engine.updateModel(str(inst), -200, m)
   return str(inst)

```

when exception occurred, in the python console view:

```
File "/home/sm/spark-1.6.1-bin-hadoop2.6/spark-1.6.1-bin hadoop2.6/spark-1.6.1-bin-hadoop2.6/python/lib/pyspark.zip/pyspark/worker.py", line 106, in process
serializer.dump_stream(func(split_index, iterator), outfile)
File "/home/sm/spark-1.6.1-bin-hadoop2.6/spark-1.6.1-bin-hadoop2.6/spark-1.6.1-bin-hadoop2.6/python/lib/pyspark.zip/pyspark/serializers.py", line 263, in dump_stream
vs = list(itertools.islice(iterator, batch))
File "/usr/local/lib/python2.7/dist-packages/spark_sklearn/grid_search.py", line 228, in fun
return_parameters=True, error_score=error_score)
File "/usr/local/lib/python2.7/dist-packages/sklearn/cross_validation.py", line 1524, in _fit_and_score
X_train, y_train = _safe_split(estimator, X, y, train)
File "/usr/local/lib/python2.7/dist-packages/sklearn/cross_validation.py", line 1585, in _safe_split

ValueError: X should be a square kernel matrix

```

I need only ValueError

Answer: 
`type(inst).__name__` will help you get the error type name. Something like this:

```
try:
    a = float('a')
except Exception as e:
    print type(e).__name__

```

Will print `ValueError`.

`str(inst)` or `inst.message` will get you the message of the error (worked always for me. But if the message isn't set, then you need to figure out another way).
I think what you are trying to say is you only need the error name. So, the aptest solution for that case would be to use **sys.exc\_info()**.
Refer: <https://docs.python.org/2/library/sys.html>