<commit_before>const libcxx_class               = 0x434C4E47432B2B00
const libcxx_dependent_class     = 0x434C4E47432B2B01
const get_vendor_and_language    = 0xFFFFFFFFFFFFFF00

const libstdcxx_class =
  bswap(reinterpret(UInt64,Uint8['G','N','U','C','C','+','+','\0'])[1])
const libstdcxx_depdendent_class =
  bswap(reinterpret(UInt64,Uint8['G','N','U','C','C','+','+','\x1'])[1])

immutable _UnwindException
    class::UInt64
    cleanup::Ptr{Void}
    private1::UInt
    private2::UInt
end

immutable LibCxxException
    referenceCount::Csize_t
    exceptionType::pcpp"std::type_info"
    exceptionDestructor::Ptr{Void}
    unexpectedHandler::Ptr{Void}
    terminate_handler::Ptr{Void}
    nextException::Ptr{Void}
    handlerCount::Cint
    handlerSwitchValue::Cint
    actionRecord::Ptr{UInt8}
    lsa::Ptr{UInt8}
    catchTemp::Ptr{Void}
    adjustedPtr::Ptr{Void}
    unwindHeader::_UnwindException
end

const LibStdCxxException = LibCxxException

immutable CxxException{kind}
    exception::Ptr{LibCxxException}
end

function exceptionObject(e::CxxException,T)
    unsafe_load(convert(Ptr{T},(e.exception+sizeof(LibCxxException))))
end

function exceptionObject{T<:CppRef}(e::CxxException,::Type{T})
    T(convert(Ptr{Void},(e.exception+sizeof(LibCxxException))))
end

import Base: showerror
function showerror(io::IO, e::CxxException)
    print(io,"Unrecognized C++ Exception")
end

function process_cxx_exception(code::UInt64, e::Ptr{Void})
    e = Ptr{_UnwindException}(e)
    if (code & get_vendor_and_language) == libcxx_class
        # This is a libc++ exception
        offset = Base.field_offset(LibCxxException,length(LibCxxException.types)-1)
        cxxe = Ptr{LibCxxException}(e - offset)
        T = unsafe_load(cxxe).exceptionType
        throw(CxxException{symbol(bytestring(icxx"$T->name();"))}(cxxe))
    elseif (code & get_vendor_and_language) == libstdcxx_class
      # This is a libstdc++ exception
      offset = Base.field_offset(LibStdCxxException,length(LibStdCxxException.types)-1)
      cxxe = Ptr{LibStdCxxException}(e - offset)
      T = unsafe_load(cxxe).exceptionType
      throw(CxxException{symbol(bytestring(icxx"$T->name();"))}(cxxe))
    end
    error("Caught a C++ exception")
end

# Get the typename, but strip refence
@generated function typename(CT, Ty)
    if Ty <: Type || Ty <: Val
        Ty = Ty.parameters[1]<commit_msg>Also print the type of unkown exceptions<commit_after>const libcxx_class               = 0x434C4E47432B2B00
const libcxx_dependent_class     = 0x434C4E47432B2B01
const get_vendor_and_language    = 0xFFFFFFFFFFFFFF00

const libstdcxx_class =
  bswap(reinterpret(UInt64,Uint8['G','N','U','C','C','+','+','\0'])[1])
const libstdcxx_depdendent_class =
  bswap(reinterpret(UInt64,Uint8['G','N','U','C','C','+','+','\x1'])[1])

immutable _UnwindException
    class::UInt64
    cleanup::Ptr{Void}
    private1::UInt
    private2::UInt
end

immutable LibCxxException
    referenceCount::Csize_t
    exceptionType::pcpp"std::type_info"
    exceptionDestructor::Ptr{Void}
    unexpectedHandler::Ptr{Void}
    terminate_handler::Ptr{Void}
    nextException::Ptr{Void}
    handlerCount::Cint
    handlerSwitchValue::Cint
    actionRecord::Ptr{UInt8}
    lsa::Ptr{UInt8}
    catchTemp::Ptr{Void}
    adjustedPtr::Ptr{Void}
    unwindHeader::_UnwindException
end

const LibStdCxxException = LibCxxException

immutable CxxException{kind}
    exception::Ptr{LibCxxException}
end

function exceptionObject(e::CxxException,T)
    unsafe_load(convert(Ptr{T},(e.exception+sizeof(LibCxxException))))
end

function exceptionObject{T<:CppRef}(e::CxxException,::Type{T})
    T(convert(Ptr{Void},(e.exception+sizeof(LibCxxException))))
end

import Base: showerror
function showerror{kind}(io::IO, e::CxxException{kind})
    print(io,"Unrecognized C++ Exception ($kind)")
end

function process_cxx_exception(code::UInt64, e::Ptr{Void})
    e = Ptr{_UnwindException}(e)
    if (code & get_vendor_and_language) == libcxx_class
        # This is a libc++ exception
        offset = Base.field_offset(LibCxxException,length(LibCxxException.types)-1)
        cxxe = Ptr{LibCxxException}(e - offset)
        T = unsafe_load(cxxe).exceptionType
        throw(CxxException{symbol(bytestring(icxx"$T->name();"))}(cxxe))
    elseif (code & get_vendor_and_language) == libstdcxx_class
        # This is a libstdc++ exception
        offset = Base.field_offset(LibStdCxxException,length(LibStdCxxException.types)-1)
        cxxe = Ptr{LibStdCxxException}(e - offset)
        T = unsafe_load(cxxe).exceptionType
        throw(CxxException{symbol(bytestring(icxx"$T->name();"))}(cxxe))
    end
    error("Caught a C++ exception")
end

# Get the typename, but strip refence
@generated function typename(CT, Ty)
    if Ty <: Type || Ty <: Val
        Ty = Ty.parameters[1]
{'fraction_non_alphanumeric': 0.13720591297105975, 'fraction_numerical': 0.020820320632937747, 'mean_word_length': 5.050377833753148, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1022441', 'n_tokens_mistral': 1704, 'n_tokens_neox': 1684, 'n_words': 256}