hugobooze Posted April 15, 2004 Posted April 15, 2004 I have a vb application with a try-catch-statement. The try-catch statement encapsulates a ShowDialog-command. When this dialog throws exceptions in debug-mode, the try-catch statement catches all errors, but if i run the exe-file it doesn't catch any errors, and a dialog box appears: "An unhandled exception has occurred in your application..." ([Details], [Continue], [Quit]) This is my code: Public Sub OpenFrmChooseObject() Try myFrmChooseObject.ShowDialog() Catch ex As Exception ... End Try End Sub Private Sub frmChooseObject_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load MsgBox(CStr(CInt("asdf"))) End Sub Any idea how to make the try-catch statement catch all errors? Quote // Hugo
be58d2003 Posted April 15, 2004 Posted April 15, 2004 Might want to be more specific as to what you are trying and what you want to catch. Quote Firefighters do it with a big hose...
JABE Posted April 15, 2004 Posted April 15, 2004 Seems to be a problem w/ the Load event; if you move the Load code to the constructor instead (Sub New), all should be well. Quote
Administrators PlausiblyDamp Posted April 15, 2004 Administrators Posted April 15, 2004 What is the code in your Catch block? When you get an unhandled exception - what type of exception is it? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
hugobooze Posted April 15, 2004 Author Posted April 15, 2004 In this example, MsgBox(CStr(CInt("asdf"))) throws an exception, but the try-catch statement doesn't catch it. No matter what code it is in the Catch block. I want to catch all exceptions which can happen then the form "myFrmChooseObject" is open (not only errors in the sub frmChooseObject_Load) This form does a lot of things, it even opens new windows, and exeptions can appear there too, but I want all this exceptions to be handled by the try-catch statement. JABE: I tryed you example (see vbcode below), but with the same result. It works when i run it in my debug environment, but when i run the exe file, the exception is not catched: Public Sub OpenFrmChooseObject() Try myFrmChooseObject = New frmChooseObject(newSessionUserASW, New Global(CurUserSK) Catch ex As Exception ... End Try End Sub Public Sub New(ByRef inUserASW As dbASWTbl_SOUser, ByRef inGlobal As Global) MyBase.New() InitializeComponent() CurUserAsw = inUserASW Global = inGlobal allowClosing = False Me.ShowDialog() End Sub Private Sub frmChooseObject_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load MsgBox(CStr(CInt("asdf"))) '(could have written "throw new Exception()" with the same result) End Sub Is there any way to make showdialog in a try-block work? Quote // Hugo
Arch4ngel Posted April 15, 2004 Posted April 15, 2004 Public Sub New(ByRef inUserASW As dbASWTbl_SOUser, ByRef inGlobal As Global) 'Try MyBase.New() InitializeComponent() CurUserAsw = inUserASW Global = inGlobal allowClosing = False Me.ShowDialog() 'Catch ex as Exception 'Doesn't feel better ? End Sub Quote "If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown "Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me "A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend. C# TO VB TRANSLATOR
hugobooze Posted April 15, 2004 Author Posted April 15, 2004 Sorry, that code gives the same result: An unhandled exception has occurred in your application. If you click Continue, the application will ignore this error and attampt to continue. If you click Quit, the application will be shut down immediately Exception of type System.Exception was thrown --------------------------------------------------------------- See the end of this message for details on invoking just-in-time (JIT) debugging instead of this dialog box. ************** Exception Text ************** System.Exception: Exception of type System.Exception was thrown. at Kasper.frmChooseObject.Button1_Click(Object sender, EventArgs e) in H:\SEHJo\Servicegrän . . . ************** JIT Debugging ************** To enable just in time (JIT) debugging, the config file for this application or machine (machine.config) must have the jitDebugging value set in the system.windows.forms section. The application must also be compiled with debugging enabled. For example: <configuration> <system.windows.forms jitDebugging="true" /> </configuration> When JIT debugging is enabled, any unhandled exception will be sent to the JIT debugger registered on the machine rather than being handled by this dialog. I've tryed to turn JIT-debugging on/off (menu - options - debugging - just-in-time) but that makes no difference Quote // Hugo
Arch4ngel Posted April 15, 2004 Posted April 15, 2004 Well man... try to Rebuild your solution and execute the right .exe (the one that is generated... don't execute another one - seems a stupid error but it happen sometime) If it's not that... It might be god :D huhu For real man I don't know what it is if it's not that. Quote "If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown "Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me "A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend. C# TO VB TRANSLATOR
JABE Posted April 16, 2004 Posted April 16, 2004 JABE: I tryed you example (see vbcode below), but with the same result. It works when i run it in my debug environment, but when i run the exe file, the exception is not catched: Try this: Public Sub OpenFrmChooseObject() Try myFrmChooseObject = New frmChooseObject(newSessionUserASW, New Global(CurUserSK) myFrmChooseObject.ShowDialog() Catch ex As Exception ... End Try End Sub Public Sub New(ByRef inUserASW As dbASWTbl_SOUser, ByRef inGlobal As Global) MyBase.New() InitializeComponent() CurUserAsw = inUserASW Global = inGlobal allowClosing = False MsgBox(CStr(CInt("asdf"))) End Sub Private Sub frmChooseObject_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load '-Code below moved to constructor. '-MsgBox(CStr(CInt("asdf"))) End Sub Quote
hugobooze Posted April 16, 2004 Author Posted April 16, 2004 Seem to be a hopeless case... JABE: Yes, of course I can move code from frmChooseObject_Load to the constructor, but that doesn't help if the exception is thrown from another sub/function in frmChooseObject. For example btn_SearchObject_click, mnu_getObjectInfo_click, txt_description_leave... I want all this code to be handled by the try-catch statement. If an exception is thrown from searchObject_click, that gives the same effect as if the exception was thrown in frmChooseObject_Load. Arch4ngel: I suppose you mean the .exe in the bin-folder. Yes that's the one I execute Quote // Hugo
hugobooze Posted April 16, 2004 Author Posted April 16, 2004 Mabye you want to know why I want to catch exceptions like this: This try-catch statement catches almost all exceptions that can appear in my program. If an exception is thrown, I the program catch the exception and mails a error description to my email address. The user also have a chance to comment what he/she did when the error happened. As soon as i get the email, i can fix the bug real quick, and deliver a bug-free version. Quote // Hugo
JABE Posted April 16, 2004 Posted April 16, 2004 Seem to be a hopeless case... JABE: Yes, of course I can move code from frmChooseObject_Load to the constructor, but that doesn't help if the exception is thrown from another sub/function in frmChooseObject. For example btn_SearchObject_click, mnu_getObjectInfo_click, txt_description_leave... I want all this code to be handled by the try-catch statement. If an exception is thrown from searchObject_click, that gives the same effect as if the exception was thrown in frmChooseObject_Load. Arch4ngel: I suppose you mean the .exe in the bin-folder. Yes that's the one I execute That's weird. I added the ff code to the frmChooseObject class: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click MsgBox(CInt("fsd")) End Sub and it was caught in the exception handler. Quote
hugobooze Posted April 16, 2004 Author Posted April 16, 2004 (edited) That's weird indeed! I attach small test solution where I test showdialog as your example show (testShowDialogInTryBlock.zip) If you run the solution in visual studio, the msgbox "Catched" appears, but if you run the exe file in the bin-folder, the dialog with the answers details/continue/quit appears. Or mabye you should send me your test codetestShowDialogInTryBlock.zip Edited March 16, 2007 by PlausiblyDamp Quote // Hugo
Arch4ngel Posted April 16, 2004 Posted April 16, 2004 Hummm... I know that even If I make a try... catch... It will ask you to Debug with VS.NET. It happened to me with an ExpirationThreadException. I do all program in C# (don't think it matters , same compiler anyway) and never had this problem. Everything goes automaticly to the Catch block. Do you have the 1.1 Version of framework ? Do you work with Visual Studio ? Which version ? I really don't know man... maybe it's an alien who curse you :D Quote "If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown "Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me "A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend. C# TO VB TRANSLATOR
hugobooze Posted April 16, 2004 Author Posted April 16, 2004 Well I have to admit I use Framework 1.0 (and Microsoft Development Environment 2002, version 7.0.9466) Mabye this is a bug solved in Framework 1.1. I will try to get Framework 1.1. I'll be Back! Thanks for all your help! Quote // Hugo
techmanbd Posted April 16, 2004 Posted April 16, 2004 From what I read around here you can't use 1.1 with 2002 Quote Live as if you were to die tomorrow. Learn as if you were to live forever. Gandhi
techmanbd Posted April 16, 2004 Posted April 16, 2004 ALSO, i have had the same problem with 1.1 and 2003 VB.NET. If I remember I got it to stop doing that but can't remember, but will look at my code and get back to you. Just have patience. ha Quote Live as if you were to die tomorrow. Learn as if you were to live forever. Gandhi
techmanbd Posted April 16, 2004 Posted April 16, 2004 OK, now I remember. check this thread out http://www.xtremedotnettalk.com/showthread.php?t=84560&highlight=turn I was having the same problem and this is how I resolved it. It is a little different than your problem, but maybe give you an idea and get you on the right track. Quote Live as if you were to die tomorrow. Learn as if you were to live forever. Gandhi
Joe Mamma Posted April 17, 2004 Posted April 17, 2004 hmmm. . . this worked for me. . . created Form1 (the startup object) and dropped a button on it. Created Form2 and added code for the load event: Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim i As Int32 i = CInt("fjkfkf") End Sub Then I added this code to the button click event: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim aform As Form2 aform = New Form2 Try aform.Show() Catch ex As Exception MsgBox("Error Occured") End Try End Sub works as expected. Man, I can't stand VB! Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
hugobooze Posted April 19, 2004 Author Posted April 19, 2004 techmanbd: Well, in that thread you linked, you replaced try-catch with thread.abort. But in my case, i have to use try-catch, because I want to catch all unexpected errors. (in that case I have to add try-catch to every single function) Joe Mamma: You use .show, I have to use .showdialog, otherwise the program pointer passes through the try-catch statement when mybase.load is ready. In that case, I can't catch errors caused by exceptions when pressing buttons i the opened form. Mabye I'm on the wrong track. What I really want to do, is to encapsulate almost my whole program in the same try-block, to catch all unexpected errors. Is there any way to do that? The code: try myMainForm.showDialog catch .. works in visual studio, but the errors isn't catched when I run the exe file. Quote // Hugo
Joe Mamma Posted April 19, 2004 Posted April 19, 2004 techmanbd: Well, in that thread you linked, you replaced try-catch with thread.abort. But in my case, i have to use try-catch, because I want to catch all unexpected errors. (in that case I have to add try-catch to every single function) Joe Mamma: You use .show, I have to use .showdialog, otherwise the program pointer passes through the try-catch statement when mybase.load is ready. In that case, I can't catch errors caused by exceptions when pressing buttons i the opened form. Mabye I'm on the wrong track. What I really want to do, is to encapsulate almost my whole program in the same try-block, to catch all unexpected errors. Is there any way to do that? The code: try myMainForm.showDialog catch .. works in visual studio, but the errors isn't catched when I run the exe file.look into Application.ThreadException Event Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
hugobooze Posted April 19, 2004 Author Posted April 19, 2004 I solved it! I solved the problem! Now the exceptions is catched even if i run the exe file. Solution:I created a textfile in the bin-folder, named testShowDialogInTryBlock.exe.config (the exe file's name was testShowDialogInTryBlock.exe). In the config file i put the text: <configuration> <system.windows.forms jitDebugging="true" /> </configuration> Then I had to compile the application in debug-mode! I was close before, but I must have made some mistake, so it didn't work then. But now I tested again, and now it worked! I think I can add this config-file in the project too. Have to test that, but in every case: Now it works! Thank you all for your help! Quote // Hugo
Joe Mamma Posted April 19, 2004 Posted April 19, 2004 I solved the problem! Now the exceptions is catched even if i run the exe file. Solution:I created a textfile in the bin-folder, named testShowDialogInTryBlock.exe.config (the exe file's name was testShowDialogInTryBlock.exe). In the config file i put the text: <configuration> <system.windows.forms jitDebugging="true" /> </configuration> Then I had to compile the application in debug-mode! I was close before, but I must have made some mistake, so it didn't work then. But now I tested again, and now it worked! I think I can add this config-file in the project too. Have to test that, but in every case: Now it works! Thank you all for your help! Thats not a solution. Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
hugobooze Posted April 19, 2004 Author Posted April 19, 2004 Almost worked... Well, my solution worked when I run the exe-file on my, or another computer with Visual Studio installed. But when I ran it on a computer with only the framework installed, the same error occurrs. Mabye the jit-debugger isn't installed when the framework is installed. I found some information about this bug. It's a bug known by Microsoft: http://support.microsoft.com/?kbid=836674 (describes the WorkAround that I described earlier in this thread) Joe Mamma: If you have another solution, please help me out! Quote // Hugo
Joe Mamma Posted April 19, 2004 Posted April 19, 2004 Well, my solution worked when I run the exe-file on my, or another computer with Visual Studio installed. But when I ran it on a computer with only the framework installed, the same error occurrs. Mabye the jit-debugger isn't installed when the framework is installed. I found some information about this bug. It's a bug known by Microsoft: http://support.microsoft.com/?kbid=836674 (describes the WorkAround that I described earlier in this thread) Joe Mamma: If you have another solution, please help me out! Assign an error handler to the static event Application.ThreadException. Enabling debugging is not recommended for your distribution release. Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.