# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import unicode_literals
import sys

from future.utils import reraise

from pyathenajdbc.error import DatabaseError, Error


def as_pandas(cursor):
    from pandas import DataFrame
    names = [metadata[0] for metadata in cursor.description]
    return DataFrame.from_records(cursor.fetchall(), columns=names)


def reraise_dbapi_error():
    exc_info = sys.exc_info()
    import jpype
    if isinstance(exc_info[1], jpype._jexception.JavaException):
        if issubclass(exc_info[1].__javaclass__, jpype.java.sql.SQLException):
            exc_type = DatabaseError
        else:
            exc_type = Error
    else:
        exc_type = exc_info[0]
    reraise(exc_type, exc_info[1], exc_info[2])

@@ -457,16 +457,40 @@
 t jpype%0A
+    value = exc_info%5B1%5D%0A
     if i
@@ -637,24 +637,257 @@
         
-exc_type
+args = exc_info%5B1%5D.args%0A            if args:%0A                cause = args%5B0%5D.cause%0A                if cause:%0A                    value = cause.getMessage()%0A                else:%0A                    value = args%5B0%5D.getMessage()%0A            tp
  = Datab
@@ -921,24 +921,18 @@
         
-exc_type
+tp
  = Error
@@ -950,24 +950,18 @@
         
-exc_type
+tp
  = exc_i
@@ -983,29 +983,17 @@
 ise(
-exc_type, exc_info%5B1%5D
+tp, value
 , ex

Update reraise handling