# Thread Errors

DevFeed: [Thread Errors](<https://devfeed.tech/articles/thread-errors-19556.md>)

Original publisher: [Read original article](<https://www.codenameone.com/blog/thread-errors/>)

Author: Shai Almog

Published: 2020-04-10T00:00:00Z

Content type: tutorial

Language: en

Sources: [CodeName One](<https://devfeed.tech/sources/codename-one.md>)

Topics: [Exception](<https://devfeed.tech/topics/exception.md>), [Concurrency](<https://devfeed.tech/topics/concurrency.md>), [Concurrent Programming](<https://devfeed.tech/topics/concurrent-programming.md>), [Code](<https://devfeed.tech/topics/code.md>), [API](<https://devfeed.tech/topics/api.md>)

Tags: [api](<https://devfeed.tech/tags/api.md>), [callback](<https://devfeed.tech/tags/callback.md>), [code](<https://devfeed.tech/tags/code.md>), [error-handling](<https://devfeed.tech/tags/error-handling.md>), [errors](<https://devfeed.tech/tags/errors.md>), [events](<https://devfeed.tech/tags/events.md>), [exception](<https://devfeed.tech/tags/exception.md>), [handler](<https://devfeed.tech/tags/handler.md>), [thread](<https://devfeed.tech/tags/thread.md>), [threading](<https://devfeed.tech/tags/threading.md>), [threads](<https://devfeed.tech/tags/threads.md>)

## AI overview

The article introduces a generic error-handling API for Codename One EasyThread. It describes global and per-thread error callbacks and notes that the methods are not thread-safe, must be invoked synchronously from one thread, and must not be called from the resulting callback.

## Source excerpt

I wrote before about EasyThread which makes it much easier to write multi-threaded code in Codename One. One problem in that scenario was the inability to define a generic exception handler for that scenario. With the current version of Codename One we now have a new generic error handling API for easy threads: public void addErrorListener(ErrorListener err); public static void addGlobalErrorListener(ErrorListener err); These methods add a callback for error events, either globally or for a specific thread. Notice that these methods aren't thread safe and should be invoked synchronously. So make sure to invoke them only from one thread e.g. the EDT.