C # try / catch a nightmare

I have an application with similar code (not written by me)

try
{
    EnumerateSomeCoolHardwareDevice();
}
catch (Exception ex)
{

} 

The UPDATE . Is this .NET C # and EnumerateSomeCoolHardwareDevice () using SerialPort?

I know how bad this code is, but it works like that for a reason!

My question is you: I see that it crashes somewhere in EnumerateSomeCoolHardwareDevice (); but it doesn’t fall into Catch (...) - it just crashes with the send dialog! It also currently only happens in release builds ... Is ANY reason for them why my exception will NOT be caught by catch (...)?

+3
source share
12 answers

, /, EnumerateSomeCoolHardwareDevice() , . , , Java .NET, , - , , , ... , , , .

+8

, EnumerateSomeCoolHardwareDevice() . , . , :

    public static void testThread()
    {
        throw new Exception("oh god it broken");
    }

    static void Main(string[] args)
    {
        try
        {
            Thread thread = new Thread(testThread);
            thread.Start();
            Console.ReadKey(); //Just to make sure we don't get out of the try-catch too soon
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
    }

, , , .

+7

.NET catch (Exception ex) .NET, .

(catching native exceptions in #) .

+3

, .NET, EnumerateSomeCoolHardwareDevice Win32 PInvoke ( ) , Native . , (, ), (, - ) , .

+2

assembly: RuntimeCompatibility (WrapNonExceptionThrows = true)

non.Net System.Exception, .

+2

, dev, DLL. . DLL - .

-, EnumerateSomeCoolHardwareDevice(), , ( /) .

, Microsoft , MS, , , ( , ).

, , , .

+1

.Net 1.1, catch ,

catch{
...
}

.Net 2.0 , System.Exception.

appdomain unhandled exception , .

+1

try..catch EnumerateSomeCoolHardwareDevice().

, , .

0

( Java) , Throwable. EnumerateSomeCoolHardwareDevice() , , .

0

, ..NET VM , , CLR. , try/catch, StackOverflowException, Debug, .

, , - , , , - ( Visual Studio, Debug/Exceptions "Thrown" "Common Language" Exuntions Runtime Exceptions ", , , catchbg.exe" catch ")

0

SerialPort, , , , - , . IIRC .DataReceived , , , . , .

.

0

? ?

, catch, ThreadAbortException.

, StackOverflowException ExecutionEngineException.

( , , , ), , , , . , .

0

Source: https://habr.com/ru/post/1725263/


All Articles