diff --git a/base/boot.jl b/base/boot.jl index 613cc686685c6..36b26024a8c9f 100644 --- a/base/boot.jl +++ b/base/boot.jl @@ -241,6 +241,10 @@ struct BoundsError <: Exception BoundsError(@nospecialize(a), i) = (@_noinline_meta; new(a,i)) end struct DivideError <: Exception end +struct FloatOverflowError <: Exception end +struct FloatUnderflowError <: Exception end +struct FloatInexactError <: Exception end +struct FloatInvalidOperationError <: Exception end struct OutOfMemoryError <: Exception end struct ReadOnlyMemoryError <: Exception end struct SegmentationFault <: Exception end diff --git a/src/init.c b/src/init.c index cf3a420d76d98..0003d19edafd0 100644 --- a/src/init.c +++ b/src/init.c @@ -842,6 +842,10 @@ void jl_get_builtin_hooks(void) jl_errorexception_type = (jl_datatype_t*)core("ErrorException"); jl_stackovf_exception = jl_new_struct_uninit((jl_datatype_t*)core("StackOverflowError")); jl_diverror_exception = jl_new_struct_uninit((jl_datatype_t*)core("DivideError")); + jl_fltovf_exception = jl_new_struct_uninit((jl_datatype_t*)core("FloatOverflowError")); + jl_fltund_exception = jl_new_struct_uninit((jl_datatype_t*)core("FloatUnderflowError")); + jl_fltres_exception = jl_new_struct_uninit((jl_datatype_t*)core("FloatInexactError")); + jl_fltinv_exception = jl_new_struct_uninit((jl_datatype_t*)core("FloatInvalidOperationError")); jl_undefref_exception = jl_new_struct_uninit((jl_datatype_t*)core("UndefRefError")); jl_undefvarerror_type = (jl_datatype_t*)core("UndefVarError"); jl_interrupt_exception = jl_new_struct_uninit((jl_datatype_t*)core("InterruptException")); diff --git a/src/jltypes.c b/src/jltypes.c index 0f0151f9c3710..3891dac3881b2 100644 --- a/src/jltypes.c +++ b/src/jltypes.c @@ -124,6 +124,10 @@ jl_value_t *jl_stackovf_exception; jl_value_t *jl_segv_exception; #endif JL_DLLEXPORT jl_value_t *jl_diverror_exception; +JL_DLLEXPORT jl_value_t *jl_fltovf_exception; +JL_DLLEXPORT jl_value_t *jl_fltund_exception; +JL_DLLEXPORT jl_value_t *jl_fltres_exception; +JL_DLLEXPORT jl_value_t *jl_fltinv_exception; JL_DLLEXPORT jl_value_t *jl_domain_exception; JL_DLLEXPORT jl_value_t *jl_overflow_exception; JL_DLLEXPORT jl_value_t *jl_undefref_exception; diff --git a/src/julia.h b/src/julia.h index fbc1eb2461b66..aea251887bec6 100644 --- a/src/julia.h +++ b/src/julia.h @@ -569,6 +569,10 @@ extern JL_DLLEXPORT jl_value_t *jl_stackovf_exception JL_GLOBALLY_ROOTED; extern JL_DLLEXPORT jl_value_t *jl_memory_exception JL_GLOBALLY_ROOTED; extern JL_DLLEXPORT jl_value_t *jl_readonlymemory_exception JL_GLOBALLY_ROOTED; extern JL_DLLEXPORT jl_value_t *jl_diverror_exception JL_GLOBALLY_ROOTED; +extern JL_DLLEXPORT jl_value_t *jl_fltovf_exception JL_GLOBALLY_ROOTED; +extern JL_DLLEXPORT jl_value_t *jl_fltund_exception JL_GLOBALLY_ROOTED; +extern JL_DLLEXPORT jl_value_t *jl_fltres_exception JL_GLOBALLY_ROOTED; +extern JL_DLLEXPORT jl_value_t *jl_fltinv_exception JL_GLOBALLY_ROOTED; extern JL_DLLEXPORT jl_value_t *jl_undefref_exception JL_GLOBALLY_ROOTED; extern JL_DLLEXPORT jl_value_t *jl_interrupt_exception JL_GLOBALLY_ROOTED; extern JL_DLLEXPORT jl_datatype_t *jl_boundserror_type JL_GLOBALLY_ROOTED; diff --git a/src/signals-unix.c b/src/signals-unix.c index 274277d32c845..205ab04c8c674 100644 --- a/src/signals-unix.c +++ b/src/signals-unix.c @@ -745,7 +745,17 @@ static void fpe_handler(int sig, siginfo_t *info, void *context) { (void)info; jl_ptls_t ptls = jl_get_ptls_states(); - jl_throw_in_ctx(ptls, jl_diverror_exception, sig, context); + jl_value_t *exc = NULL; + switch (info->si_code) + { + case FPE_FLTDIV: exc = jl_diverror_exception; break; // Floating-point divide by zero. + case FPE_FLTOVF: exc = jl_fltovf_exception; break; // Floating-point overflow. + case FPE_FLTUND: exc = jl_fltund_exception; break; // Floating-point underflow. + case FPE_FLTRES: exc = jl_fltres_exception; break; // Floating-point inexact result. + case FPE_FLTINV: exc = jl_fltinv_exception; break; // Floating-point invalid operation. + default: exc = jl_diverror_exception; assert(0); + } + jl_throw_in_ctx(ptls, exc, sig, context); } static void sigint_handler(int sig)