logo
down
shadow

Can one C# Exception be thrown multiple times on different threads?


Can one C# Exception be thrown multiple times on different threads?

By : janh
Date : November 17 2020, 11:52 AM
Hope this helps
is it safe to throw one exception object several times on multiple threads?
code :


Share : facebook icon twitter icon
Capture stacktrace for all threads when an exception is thrown

Capture stacktrace for all threads when an exception is thrown


By : Abdullah
Date : March 29 2020, 07:55 AM
Does that help In order to catch the stack traces of the other threads, you'd have to be in the debugger and view their stacks (e.g. with Parallel Stack Window) when the exception is thrown, but that doesn't let you send their traces back.
You could instrument your code (i.e. pepper it in strategic locations) to record stack traces the other thread can get to, but this has nasty performance, maintenance, and elegance issues. Not to mention it would only approximate what the other threads are doing, since they could have advanced independently since the exception was thrown.
How know with GPars that all threads have finished when an exception is thrown?

How know with GPars that all threads have finished when an exception is thrown?


By : Pradeep Reddy
Date : March 29 2020, 07:55 AM
it should still fix some issue I believe I have a solution for the problem, I implemented it in the application after thorough testing and it works.
The withPool closure passes in the created pool (a jsr166y.ForkJoinPool) as the first argument. I can grab that and store it off in a variable (currentPool), to be used later by the main thread, like so:
code :
    GParsPool.withPool { pool ->
        currentPool = pool
    } catch (Exception exc) {
        if (currentPool) {
            while (!currentPool.isQuiescent()) {
                Thread.sleep(100)
                println 'waiting for threads to finish'
            }
        }

        println 'all done'
    }
void example() {
    jsr166y.ForkJoinPool currentPool

    AtomicInteger threadCounter = new AtomicInteger(0)
    AtomicInteger threadCounterEnd = new AtomicInteger(0)

    AtomicReference<Exception> realException = new AtomicReference<Exception>()

    try {
        GParsPool.withPool { pool ->
            currentPool = pool

            (1..500).eachParallel {
                try {
                    if (threadCounter.incrementAndGet() == 1) {
                        throw new RuntimeException('planet blew up!')
                    }

                    if (realException.get() != null) {
                        // We had an exception already in this eachParallel - quit early
                        return
                    }

                    // Do some long work
                    Integer counter=0
                    (1..1000000).each() {counter++}

                    // Flag if we went all the way through
                    threadCounterEnd.incrementAndGet()
                } catch (Exception exc) {
                    realException.compareAndSet(null, exc)

                    pool.shutdownNow()
                    throw realException
                }
            }
        }
    } catch (Exception exc) {
        // If we used pool.shutdownNow(), we need to look at the real exception.
        // This is needed because pool.shutdownNow() sometimes generates a CancellationException
        // which can cover up the real exception that caused us to do a shutdownNow().
        if (realException.get()) {
            exc = realException.get()
        }

        if (currentPool) {
            while (!currentPool.isQuiescent()) {
                Thread.sleep(100)
                println 'waiting for threads to finish'
            }
        }

        // Do further exception handling here...
        exc.printStackTrace()
    }
}
Threads - why exception is thrown at runtime?

Threads - why exception is thrown at runtime?


By : Novice
Date : March 29 2020, 07:55 AM
it should still fix some issue If you're ensuring that there is an instance of Chicks in each instance of ChicksYack, then you need to move the line:
code :
c= new Chicks();
public ChicksYack() {
    c= new Chicks();
}
static Chicks c;
Exception being thrown multiple times

Exception being thrown multiple times


By : canadianultra
Date : March 29 2020, 07:55 AM
I hope this helps . Basically I am ting to catch any exception off a block of code, and fire said code one. , I was making multiple timers. So it overlapped.
how can I count the number of exception thrown by threads?

how can I count the number of exception thrown by threads?


By : Bunnie Hsieh
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further When you execute get() on Future you might get ExecutionException, then just use getCause() which will return actual exception.
Related Posts Related Posts :
  • I am trying to do a while loop with a string conditional statement in C#
  • C# 'Cannot access a disposed object. Object name: 'SslStream'.'
  • How to make Gecko use seperate CookieContainer per instance?
  • C# Advanced form "please wait"
  • Send and Receive data C# using network stream
  • How to discover that appsettings changed in C#?
  • Check what needs full trust
  • What is the execution order of an MVC Razor view/layout
  • Table designer (Entity Framework) is too resource intense
  • How to clean up an exception string so it can be displayed via Javascript Alert?
  • Configuring Amazon SES Feedback Notifications via Amazon SNS in ASP.NET MVC (C#)
  • C# api responce and request
  • Dynamodb putitem function not working properly
  • theme in windows phone(light or dark) using c#
  • Backup attached database file(.mdf) using c# and SQL Server
  • What is 'TextFile' and where it is uses in WPF project
  • Using same alias for multiple namespaces
  • how to move mails into separate folders
  • Multithreaded Uploader
  • Memory fragmentation?
  • C# correct exception handling
  • "Could not open macro storage" when accessing using file on another machine
  • How to access other directories of hosted server
  • C# Jagged Array check if value exists/true
  • Why can't I type Clone() properly?
  • exception on accessing dictionary from list
  • Getting the immediate response from server without waiting to 200 message
  • Why am I getting exception Directory Is Not empty?
  • Could not load file or assembly 'CefSharp.dll' or one of its dependencies
  • Sending Email By Using C# in unity3D?
  • Correct usage of await async in webapi
  • Program update code issue
  • Marshal.Copy attempted to read or write protected memory At Random Times
  • Restrict Type variable to specific class or subclass
  • Horizontal text alignment in a PdfPCell
  • C# crashing with Form.show() command, ObjectDisposedException - Deeper look / explanation please
  • Will the result of a LINQ query always be guaranteed to be in the correct order?
  • "Could not find default endpoint element that references contract"
  • Umbraco Request.QueryString is null if it's the first time the page is loaded
  • Error inconsistent accessibility method C#
  • How to program Intel Xeon Phi with C#?
  • remove nested element using regular expression
  • Is there a C# alternative to Java's vararg parameters?
  • Clear particular column values in DataTable
  • how to add event handler to programatically created checkboxes
  • Cannot apply indexing with [] to an expression of type 'System.Collections.Specialized.NameValueCollection'
  • Check for key in pre-existing dictionary in case insensitive manner
  • How to remove year from datetime object?
  • Accessing Settings in different ways
  • "This project is empty" error in Sonarqube
  • How to create reusable icon menu in Xamarin
  • Value Cannot be null in Ado.Net connectivity
  • Adding a custom/dynamic attribute when using XSD.exe
  • How to convert object to correct type
  • Automatically sign out from Forms Authentication in ASP.NET when browser is closed
  • Can a WCF service support both Buffered and Streamed transfer modes?
  • Verify a CA Certificate with a public key in C#
  • How to invoke a Web Service that requires the "patch" verb using the C# WebClient wrapper?
  • Proper way a implementing property based on generic type
  • Closing a form that is created in another thread
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org