# Cxx.jl calling the Julia error function from C++

**URL:** <https://discourse.julialang.org/t/cxx-jl-calling-the-julia-error-function-from-c/26449>\
**Category:** General Usage\
**Tags:** cxx\
**Created:** [July 17, 2019, 5:00am UTC](https://discourse.julialang.org/t/cxx-jl-calling-the-julia-error-function-from-c/26449 "2019-07-17T05:00:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ethomag](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ethomag/32/421_2.png) [@ethomag](https://discourse.julialang.org/u/ethomag)\
**Post date:** [July 17, 2019, 5:00am UTC](https://discourse.julialang.org/t/cxx-jl-calling-the-julia-error-function-from-c/26449/1 "2019-07-17T05:00:39Z")

</div>

I am trying to propagate an error from C++ to Julia. From the Cxx.jl documentation, I found (which works fine):

> julia\> cxx"“”  
> void testJuliaPrint() {  
> $:(println(“\nTo end this test, press any key”)::Nothing);  
> }  
> “”"

Trying the same with the Julia `error()` function:

> julia\> cxx"“”  
> void testJuliaError() {  
> $:(error(“ERROR”)::Nothing);  
> }  
> “”"

Results in (which I am not competent to interpret):

> ERROR: Inferred Union or abstract type Union{} for return value of lambda  
> Stacktrace:  
> [1] error(::String) at ./error.jl:33  
> [2] cpptype(::Cxx.CxxCore.ClangCompiler, ::Type{getfield(Main, Symbol(“##42#43”))}) typetranslation.jl:302  
> [3] ssv(::Cxx.CxxCore.ClangCompiler, ::Any, ::Cxx.CxxCore.CppPtr{Cxx.CxxCore.CxxQualType{Cxx.CxxCore.CppBaseType{Symbol(“clang::DeclContext”)},(false, false, false)},(false, false, false)}, ::Int64, ::Base.GenericIOBuffer{Array{UInt8,1}}, ::Dict{Nothing,Nothing}) cxxstr.jl:56  
> [4] ssv(::Cxx.CxxCore.ClangCompiler, ::Any, ::Cxx.CxxCore.CppPtr{Cxx.CxxCore.CxxQualType{Cxx.CxxCore.CppBaseType{Symbol(“clang::DeclContext”)},(false, false, false)},(false, false, false)}, ::Int64, ::Base.GenericIOBuffer{Array{UInt8,1}}) at cxxstr.jl:40  
> [5] top-level scope at cxxstr.jl:641

Actually, `println()` is the only function I have found to be callable from C++. Any ideas how to propagate an error condition from C++ to Julia ?

---

<div class="post-metadata">

**Author:** ![Gnimuc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gnimuc/32/2194_2.png) [@Gnimuc](https://discourse.julialang.org/u/Gnimuc)\
**Post date:** [July 17, 2019, 1:05pm UTC](https://discourse.julialang.org/t/cxx-jl-calling-the-julia-error-function-from-c/26449/2 "2019-07-17T13:05:03Z")

</div>

X-ref: [Calling Julia Base.error() from C++ · Issue #433 · JuliaInterop/Cxx.jl · GitHub](https://github.com/JuliaInterop/Cxx.jl/issues/433)

> [@ethomag](#):
>
> Actually, `println()` is the only function I have found to be callable from C++.

what do you mean? could you post those failed examples?

```julia
julia> using Cxx

julia> cxx"""
          float cxxsin() {
              return $:(sin(x)::Float32);
          }
       """
true

julia> x = 0.5f0
0.5f0

julia> @cxx cxxsin()
0.47942555f0

```
