# Why can't I catch the following error?

**URL:** <https://discourse.julialang.org/t/why-cant-i-catch-the-following-error/121712>\
**Category:** New to Julia\
**Created:** [October 24, 2024, 5:04pm UTC](https://discourse.julialang.org/t/why-cant-i-catch-the-following-error/121712 "2024-10-24T17:04:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![deusexlibris](https://avatars.discourse-cdn.com/v4/letter/d/ba8739/32.png) [@deusexlibris](https://discourse.julialang.org/u/deusexlibris)\
**Post date:** [October 24, 2024, 5:04pm UTC](https://discourse.julialang.org/t/why-cant-i-catch-the-following-error/121712/1 "2024-10-24T17:04:42Z")

</div>

I have created a simple web server using HTTP.jl for handling high-volume, low-latency simple requests. For performance, I spawn a separate thread on :default for each request.

Everything runs fine but after running tests using 200 concurrent connections, I get the following error when the requester stops sending requests:

┌ Error: handle\_connection handler error.  
│  
│ ===========================  
│ HTTP Error message:  
│  
│ ERROR: IOError: write: connection reset by peer (ECONNRESET)  
│ Stacktrace:  
│ [1] uv\_write(s::Sockets.TCPSocket, p::Ptr{UInt8}, n::UInt64)  
---- removed as forum software thought I was posting links  
│  
│ “”"  
└ @ HTTP.Servers ~/usr/local/julia/reg/packages/HTTP/sJD5V/src/Servers.jl:483

I am not so concerned about the error itself as it could be that the test tool is dropping the connection. However, I am trying to catch these errors so it doesn’t clutter my logs, since this application could have thousands of connections. Here is the basic structure of the app:

function main()  
global server\_ready, http\_server\_port, http\_max\_conns, http\_readtimeout  
try  
server\_ready = true  
HTTP.serve(ROUTER, “0.0.0.0”, http\_server\_port, stream=true, max\_connections=http\_max\_conns, readtimeout=http\_readtimeout)  
catch  
if isa(e, Base.IOError) && e.code == Base.UV\_EPIPE  
println(“Broken Pipe Error - Ignored”)  
else  
rethrow()  
end  
end  
end

try  
main()  
catch e  
println(“Error in main server loop”)  
showerror(stdout, e)  
end

However, when the connection reset error occurs, it is not caught by my exception handling code, regardless of how I structure it.

---

<div class="post-metadata">

**Author:** ![Sevi](https://avatars.discourse-cdn.com/v4/letter/s/c67d28/32.png) [@Sevi](https://discourse.julialang.org/u/Sevi)\
**Post date:** [October 24, 2024, 7:20pm UTC](https://discourse.julialang.org/t/why-cant-i-catch-the-following-error/121712/2 "2024-10-24T19:20:02Z")

</div>

Hi and welcome to the forum 👋

Please consider wrapping your code and terminal output in backticks (as described here: [Please read: make it easier to help you](https://discourse.julialang.org/t/please-read-make-it-easier-to-help-you/14757) ) for easier readability 🙂

Regarding your actual problem:

- What exactly is your desired output? If I understand correctly, your code should print `"Broken Pipe Error - Ignored"` if you encounter the error you mentioned, but keep running? What is the behavior you see instead? (exception/no exception; exact error message)
- I think your code as-is should probably throw an `UndefVarError` if the HTTP error occurs because your catch block inside `main()` doesn’t assign the variable `e`. Are there some parts of the code missing?

---

<div class="post-metadata">

**Author:** ![deusexlibris](https://avatars.discourse-cdn.com/v4/letter/d/ba8739/32.png) [@deusexlibris](https://discourse.julialang.org/u/deusexlibris)\
**Post date:** [October 26, 2024, 6:46pm UTC](https://discourse.julialang.org/t/why-cant-i-catch-the-following-error/121712/3 "2024-10-26T18:46:18Z")

</div>

Thanks for the reply. I will pay more attention to formatting in future posts.

You are correct with what I am looking to see but what I get is either the `handle connection error` I posted or an equivalent `Broken Pipe` error.

Your second point is also correct (thanks!) but reinforces the idea that the exception isn’t being caught by my try/catch. I have fixed it and will test again to see if the try/catch was being ignored because of this.

---

<div class="post-metadata">

**Author:** ![BioTurboNick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bioturbonick/32/6380_2.png) [@BioTurboNick](https://discourse.julialang.org/u/BioTurboNick)\
**Post date:** [October 26, 2024, 6:55pm UTC](https://discourse.julialang.org/t/why-cant-i-catch-the-following-error/121712/4 "2024-10-26T18:55:04Z")

</div>

Errors that are wrapped in a bracket like that probably come from the `@error` logging macros. The underlying exception is handled and logged by the underlying library and not available to the calling code. There’s presumably a non-exception-handling way to retrieve the status for an HTTP error for programmatic handling of the error.

EDIT: And also probably a way to control the logging of said errors.

---

<div class="post-metadata">

**Author:** ![deusexlibris](https://avatars.discourse-cdn.com/v4/letter/d/ba8739/32.png) [@deusexlibris](https://discourse.julialang.org/u/deusexlibris)\
**Post date:** [October 26, 2024, 9:19pm UTC](https://discourse.julialang.org/t/why-cant-i-catch-the-following-error/121712/5 "2024-10-26T21:19:01Z")

</div>

I figured out that HTTP.jl uses LoggingExtras. I was able to suppress these error messages using an ActiveFilteredLogger.

Thanks for the help.
