UnhandledException
-
Does anyone know why this code doenst work?(In a consonle Application) it cant catch exceptions static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyException); throw new ArgumentException("for test"); } static void MyException(object sender, UnhandledExceptionEventArgs e) { Console.WriteLine(e.ExceptionObject); } } Thanks
Of one Essence is the human race thus has Creation put the base One Limb impacted is sufficient For all Others to feel the Mace (Saadi )
-
Does anyone know why this code doenst work?(In a consonle Application) it cant catch exceptions static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyException); throw new ArgumentException("for test"); } static void MyException(object sender, UnhandledExceptionEventArgs e) { Console.WriteLine(e.ExceptionObject); } } Thanks
Of one Essence is the human race thus has Creation put the base One Limb impacted is sufficient For all Others to feel the Mace (Saadi )
What do you mean "doesn't work"? I just tried it and it does what I would expect.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
-
Does anyone know why this code doenst work?(In a consonle Application) it cant catch exceptions static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyException); throw new ArgumentException("for test"); } static void MyException(object sender, UnhandledExceptionEventArgs e) { Console.WriteLine(e.ExceptionObject); } } Thanks
Of one Essence is the human race thus has Creation put the base One Limb impacted is sufficient For all Others to feel the Mace (Saadi )
static void Main(string\[\] args) { AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyException); throw new ArgumentException("for test"); } static void MyException(object sender, UnhandledExceptionEventArgs e) { Console.WriteLine("CAUGHT: " + e.ExceptionObject.ToString()); }
Works for me; displays the exception with the custom text in the console, and then switches to the debugger. What did you expect it to do, and what behaviour are you observing?
Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]
-
What do you mean "doesn't work"? I just tried it and it does what I would expect.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
Im wonderful it cant catgh any unhandled exceptions and clr shows unhandled exception windows when I see event viewer it shows these info about my program Faulting application name: Mydynamic.exe, version: 1.0.0.0, time stamp: 0x507ac6d7 Faulting module name: KERNELBASE.dll, version: 6.1.7601.17514, time stamp: 0x4ce7bafa Exception code: 0xe0434352 Fault offset: 0x0000b727 Faulting process id: 0x4b4 Faulting module path: F:\Windows\syswow64\KERNELBASE.dll Report Id: 81b9c3ff-1608-11e2-bc0d-005056c00008 I dont have this problem in other programs(like WPF,Windows Forms or ASP.Net) it works for them and donest work for console applications
Of one Essence is the human race thus has Creation put the base One Limb impacted is sufficient For all Others to feel the Mace (Saadi )
-
static void Main(string\[\] args) { AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyException); throw new ArgumentException("for test"); } static void MyException(object sender, UnhandledExceptionEventArgs e) { Console.WriteLine("CAUGHT: " + e.ExceptionObject.ToString()); }
Works for me; displays the exception with the custom text in the console, and then switches to the debugger. What did you expect it to do, and what behaviour are you observing?
Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]
Its the result of event viewver Faulting application name: Mydynamic.exe, version: 1.0.0.0, time stamp: 0x507ac6d7 Faulting module name: KERNELBASE.dll, version: 6.1.7601.17514, time stamp: 0x4ce7bafa Exception code: 0xe0434352 Fault offset: 0x0000b727 Faulting process id: 0x4b4 Faulting application start time: 0x01cdaa154403b39d Faulting application path: c:\users\apple\documents\visual studio 2010\Projects\Mydynamic\Mydynamic\bin\Debug\Mydynamic.exe Faulting module path: F:\Windows\syswow64\KERNELBASE.dll Report Id: 81b9c3ff-1608-11e2-bc0d-005056c00008 but I dont know why the path is c:\ all my programs are on f:\
Of one Essence is the human race thus has Creation put the base One Limb impacted is sufficient For all Others to feel the Mace (Saadi )
-
Its the result of event viewver Faulting application name: Mydynamic.exe, version: 1.0.0.0, time stamp: 0x507ac6d7 Faulting module name: KERNELBASE.dll, version: 6.1.7601.17514, time stamp: 0x4ce7bafa Exception code: 0xe0434352 Fault offset: 0x0000b727 Faulting process id: 0x4b4 Faulting application start time: 0x01cdaa154403b39d Faulting application path: c:\users\apple\documents\visual studio 2010\Projects\Mydynamic\Mydynamic\bin\Debug\Mydynamic.exe Faulting module path: F:\Windows\syswow64\KERNELBASE.dll Report Id: 81b9c3ff-1608-11e2-bc0d-005056c00008 but I dont know why the path is c:\ all my programs are on f:\
Of one Essence is the human race thus has Creation put the base One Limb impacted is sufficient For all Others to feel the Mace (Saadi )
Hamid. wrote:
Its the result of event viewver
Doesn't contain much hints on what went wrong. I hope you're logging the full text of the exceptions?
Hamid. wrote:
Faulting application path: c:\users\apple\documents\visual studio 2010\Projects\Mydynamic\Mydynamic\bin\Debug\Mydynamic.exe
Faulting module path: F:\Windows\syswow64\KERNELBASE.dll
Report Id: 81b9c3ff-1608-11e2-bc0d-005056c00008
but I dont know why the path is c:\ all my programs are on f:\Looks like it's (also) being run from Visual Studio, debugging on it's C-drive.
Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]
-
Im wonderful it cant catgh any unhandled exceptions and clr shows unhandled exception windows when I see event viewer it shows these info about my program Faulting application name: Mydynamic.exe, version: 1.0.0.0, time stamp: 0x507ac6d7 Faulting module name: KERNELBASE.dll, version: 6.1.7601.17514, time stamp: 0x4ce7bafa Exception code: 0xe0434352 Fault offset: 0x0000b727 Faulting process id: 0x4b4 Faulting module path: F:\Windows\syswow64\KERNELBASE.dll Report Id: 81b9c3ff-1608-11e2-bc0d-005056c00008 I dont have this problem in other programs(like WPF,Windows Forms or ASP.Net) it works for them and donest work for console applications
Of one Essence is the human race thus has Creation put the base One Limb impacted is sufficient For all Others to feel the Mace (Saadi )
My complete test code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyException);throw new ArgumentException("for test"); } static void MyException(object sender, UnhandledExceptionEventArgs e) { Console.WriteLine("Exception Caught!"); Environment.Exit(0); } } }
My complete CMD output:
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.C:\Users\griff>d:
D:\>cd \temp
D:\Temp>ca
Exception Caught!D:\Temp>
What am I doing that differs from you?
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
-
My complete test code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyException);throw new ArgumentException("for test"); } static void MyException(object sender, UnhandledExceptionEventArgs e) { Console.WriteLine("Exception Caught!"); Environment.Exit(0); } } }
My complete CMD output:
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.C:\Users\griff>d:
D:\>cd \temp
D:\Temp>ca
Exception Caught!D:\Temp>
What am I doing that differs from you?
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
My code is the same with your code except (Environment.Exit(0); (I dont have this code) it works with this code but without it I got this message of e.ExceptionObject System.ArgumentException: for test at ConsoleApplication1.Program.Main(String[] args) in c:\users\apple\documents\visual studio 2010\Projects\Mydynamic\Mydynamic\Program.cs:line 17 and it shows this window Windows can check online for a solution to the problems. Check online for a solution and close the program Close the program Debug the problem when I click on the "Debug the problem" item, visual sutdio Just In-Time debugger asks "Do you want to debug using the selected debugger?" after yes it goes to my code exception details are System.ArgumentException was unhandled Message=for test Source=Mydynamic StackTrace: at ConsoleApplication1.Program.Main(String[] args) in c:\users\apple\documents\visual studio 2010\Projects\Mydynamic\Mydynamic\Program.cs:line 17 InnerException:
Of one Essence is the human race thus has Creation put the base One Limb impacted is sufficient For all Others to feel the Mace (Saadi )
-
Hamid. wrote:
Its the result of event viewver
Doesn't contain much hints on what went wrong. I hope you're logging the full text of the exceptions?
Hamid. wrote:
Faulting application path: c:\users\apple\documents\visual studio 2010\Projects\Mydynamic\Mydynamic\bin\Debug\Mydynamic.exe
Faulting module path: F:\Windows\syswow64\KERNELBASE.dll
Report Id: 81b9c3ff-1608-11e2-bc0d-005056c00008
but I dont know why the path is c:\ all my programs are on f:\Looks like it's (also) being run from Visual Studio, debugging on it's C-drive.
Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]
Im using of visual studio 2010 SP1 I got this message of e.ExceptionObject System.ArgumentException: for test at ConsoleApplication1.Program.Main(String[] args) in c:\users\apple\documents\visual studio 2010\Projects\Mydynamic\Mydynamic\Program.cs:line 17 and it clr shows this window Windows can check online for a solution to the problems. Check online for a solution and close the program Close the program Debug the problem when I click on the "Debug the problem" item, visual sutdio Just In-Time debugger asks "Do you want to debug using the selected debugger?" after yes it goes to my code exception details are System.ArgumentException was unhandled Message=for test Source=Mydynamic StackTrace: at ConsoleApplication1.Program.Main(String[] args) in c:\users\apple\documents\visual studio 2010\Projects\Mydynamic\Mydynamic\Program.cs:line 17 InnerException:
Of one Essence is the human race thus has Creation put the base One Limb impacted is sufficient For all Others to feel the Mace (Saadi )
-
My code is the same with your code except (Environment.Exit(0); (I dont have this code) it works with this code but without it I got this message of e.ExceptionObject System.ArgumentException: for test at ConsoleApplication1.Program.Main(String[] args) in c:\users\apple\documents\visual studio 2010\Projects\Mydynamic\Mydynamic\Program.cs:line 17 and it shows this window Windows can check online for a solution to the problems. Check online for a solution and close the program Close the program Debug the problem when I click on the "Debug the problem" item, visual sutdio Just In-Time debugger asks "Do you want to debug using the selected debugger?" after yes it goes to my code exception details are System.ArgumentException was unhandled Message=for test Source=Mydynamic StackTrace: at ConsoleApplication1.Program.Main(String[] args) in c:\users\apple\documents\visual studio 2010\Projects\Mydynamic\Mydynamic\Program.cs:line 17 InnerException:
Of one Essence is the human race thus has Creation put the base One Limb impacted is sufficient For all Others to feel the Mace (Saadi )
That is pretty much what I would expect. If you don't have the exception handler cause an program exit, then the system has no choice except to cause an abnormal termination - which is what your message shows. Think about it: the exception is thrown from the Main method. The application cannot continue under any circumstances without restarting the whole program. In Winforms et al., it is multithreaded, so a single thread can be terminated without necessarily killing the whole app - but your console app is a single thread. If it can't continue the only running thread, it can't continue the application. In GUI apps, the Main function is executed in a thread, which fires off other threads to handle the UI for each form. They can be terminated without affecting the Main thread, since all it is doing is waiting for the others to die anyway! :laugh:
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
-
That is pretty much what I would expect. If you don't have the exception handler cause an program exit, then the system has no choice except to cause an abnormal termination - which is what your message shows. Think about it: the exception is thrown from the Main method. The application cannot continue under any circumstances without restarting the whole program. In Winforms et al., it is multithreaded, so a single thread can be terminated without necessarily killing the whole app - but your console app is a single thread. If it can't continue the only running thread, it can't continue the application. In GUI apps, the Main function is executed in a thread, which fires off other threads to handle the UI for each form. They can be terminated without affecting the Main thread, since all it is doing is waiting for the others to die anyway! :laugh:
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
A question I am making a new thread so my program have two threads (main thread) and worker thread then I am testing this code but the problem is same ? could you explain it ? Thanks
Of one Essence is the human race thus has Creation put the base One Limb impacted is sufficient For all Others to feel the Mace (Saadi )
-
A question I am making a new thread so my program have two threads (main thread) and worker thread then I am testing this code but the problem is same ? could you explain it ? Thanks
Of one Essence is the human race thus has Creation put the base One Limb impacted is sufficient For all Others to feel the Mace (Saadi )
-
Im using of visual studio 2010 SP1 I got this message of e.ExceptionObject System.ArgumentException: for test at ConsoleApplication1.Program.Main(String[] args) in c:\users\apple\documents\visual studio 2010\Projects\Mydynamic\Mydynamic\Program.cs:line 17 and it clr shows this window Windows can check online for a solution to the problems. Check online for a solution and close the program Close the program Debug the problem when I click on the "Debug the problem" item, visual sutdio Just In-Time debugger asks "Do you want to debug using the selected debugger?" after yes it goes to my code exception details are System.ArgumentException was unhandled Message=for test Source=Mydynamic StackTrace: at ConsoleApplication1.Program.Main(String[] args) in c:\users\apple\documents\visual studio 2010\Projects\Mydynamic\Mydynamic\Program.cs:line 17 InnerException:
Of one Essence is the human race thus has Creation put the base One Limb impacted is sufficient For all Others to feel the Mace (Saadi )