I have a lot of shortlived threads that updates my program, by events fired from a socket connection. My problem is I don't know how to debug this, like how to get the proper information on where in the code the exceptions occur. Because I get for example an exception like below, and this will just be the print in the Immidiate Window. There is no pop-up window, and it does not highlight any line in the code or show even what method it was in.
What am I missing? What I can do to see these things? And what improvements does VS2010 give on this situation, if any?
A first chance exception of type 'System.InvalidOperationException' occurred in System.Core.dll
A first chance exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll
A first chance exception of type 'System.Threading.ThreadAbortException' occurred in Krs.Ats.IBNet.dll
Go to "Debug -> Exceptions...", locate the "Common Language Runtime Exceptions" and check the "Thrown" mark. Now start debugging your application. Once any of CLR exception occurs the execution will stop on that line.
Related
Why do we catch NoSuchElementException? It makes sense to catch the exception when we only verify the presence of an element in a particular page and not performing any actions on it. We can catch this exception and log a custom message like "Element not found"
When we are about to click an element and if it is not found in the page, selenium throws NoSuchElementException. What is the use of catching this exception instead of letting it to halt the test and failing the testcase?
Note: My subsequent steps depends on this clicking step.
One reason to catch the exception is to provide more relevant test failure output. For example, if a div element isn't found in a page of 20-30 divs, cause the selector doesn't match that specific div, you could let the exception remain uncaught with a generic error message or you could catch it and throw a different exception with error message "navbar is missing".
If it is clear from the generic error message what is wrong, or you have a test failure message that explains it, there is no reason to catch it.
A different reason to catch this exception is that it's part of skip code (skip this test if/unless). So you look for an element and if it's present you proceed with the test, if it's not - you skip it.
There may be other reasons, but these are two common ones.
There are two types of Exceptions:
1.Checked Exceptions
2.Unchecked Exceptions
Checked Exceptions are checked at compile time only, these should be handled by the programmer. Compiler will check at compile time whether these exceptions are handled or not if not compile time error occurs. Some of the checked exceptions are IOException, FileNotFoundExpection,etc.
Unchecked Exceptions:
Unchecked exceptions are not checked by compiler at the time of compilation. the exceptions which are extended by RuntimeException class are all unchecked exceptions. Some of the unchecked exceptions are AritmeticException, NullPointerException etc. In selenium we see unchecked exceptions such as NoSuchElementException, StaleElementReferenceException , NoSuchWindowException, TimeoutException etc.
In short, Checked exceptions must be caught. RuntimeException, also called unchecked exceptions, should not be caught
More info can be found on
http://toolsqa.com/selenium-webdriver/exception-handling-selenium-webdriver/
http://www.seleniumeasy.com/java-tutorials/exception-handling-in-selenium-webdriver-using-java-examples
I'm running Azure Service Bus as a transport with NServiceBus. In my Visual Studio Output window, I am getting tons of exceptions thrown. They don't appear to actually be causing any issues with the system, everything works fine. They fire off every 25-30 seconds, so as you can imagine, this really clutters my output log and makes it difficult to read.
This is a sample of what gets printed every 30 seconds or so. This is only a small section of the total lines, roughly about 50-70 lines of FaultException and TimeoutExceptions in no particular order :
Exception thrown: 'System.ServiceModel.FaultException'1' in Microsoft.ServiceBus.dll
Exception thrown: 'System.ServiceModel.FaultException1' in Microsoft.ServiceBus.dll
Exception thrown: 'System.ServiceModel.FaultException1' in Microsoft.ServiceBus.dll
Exception thrown: 'System.ServiceModel.FaultException1' in Microsoft.ServiceBus.dll
Exception thrown: 'System.ServiceModel.FaultException1' in Microsoft.ServiceBus.dll
Exception thrown: 'System.TimeoutException' in Microsoft.ServiceBus.dll
I was able to resolve this by checking "Enable Just My Code" in Tools -> Options -> Debugging -> General.
If I have a main procedure with error handling that calls other procedures without error handling, should errors roll up to the main procedure?
What if the procedures without error handling use functions without error handling?
Should everything roll up to the main procedure's error handling?
Yes, unhandled errors will roll up the stack. If you have no error-handling in your main routine (or in the current event-handling routine), then the error will roll up to VBA itself, which will either cause your program to abort, or reset the VBA environment within the host applicaton. (you don't want that).
I can think of two apparent exceptions to this: one illusory and one real:
1) If VBA is entered through an unanticipated event-path, instead of though the main routine, it may appear that your Main-routines error-handler is being bypassed by the error-return, but in reality, it's another thread, so when it rolls-up from an event-handler, it goes to VBA independently of your Main routine's main-thread.
2) The VBA error-handling cannot catch ALL errors, in particular, most FATAL errors cannot be caught by it and crash (and reset) the whole VBA environment. "Stack Overflow" errors are an example.
Procedure A with error-handling will catch all errors. Procedure B with no error-handling will catch none.
If A calls B and B has an error, it will roll up and be caught in A's handler.
If B calls A and B has an error, there won't be any handling.
If B calls A and A has an error, A will catch it.
Whether it's a function or a procedure makes no difference. However it's worth noting that a class module won't handle errors locally, but passes them back up the stack to the first non-class module.
I'm not sure what you mean by "should," but where you want an error caught can depend on what you want to do with the error. For example, if a certain error requires you to make a small tweak on a string and then resume where you were, then you want very local handling. In other cases, simplicity might call for top-level handling.
Errors not locally handled will always* get trapped by the up-the-stack error handler if the error trapping option is set to "Break on Unhandled Errors". You'll find this setting in the IDE under Tools Options.
If it's set to "Break on All Errors", no error handler (neither local or up-the-stack) will be called. If it's set to "Break in Class Module", no out-of-class error handler will be called for in-class error.
Note that this option change the line on which the debugger stops: when an unhandled error occurs in a class module, the debugger stops on the line calling the class with "Break on Unhandled Errors" or on the offending line in the class with "Break in Class Module".
In Access, this option can be read programmatically with Application.GetOption("Error Trapping") and Application.SetOption("Error Trapping").
*As RBarryYoung has written, the most fatal errors (like stack overflow errors) won't be caught by any VBA error-handling.
I have a project that runs perfect under windows xp.
Now I have tried to run it under Windows 7 and got there a lot of exceptions under Immediate window.
A first chance exception of type 'System.ArgumentNullException' occurred in Microsoft.VisualBasic.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in LP_Wizard.exe
A first chance exception of type 'System.ArgumentException' occurred in LP_Wizard.exe
A first chance exception of type 'System.NullReferenceException' occurred in LP_Wizard.exe
A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll
A first chance exception of type 'System.ArgumentNullException' occurred in Microsoft.VisualBasic.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in LP_Wizard.exe
A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll
A first chance exception of type 'System.ArgumentNullException' occurred in Microsoft.VisualBasic.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in LP_Wizard.exe
A first chance exception of type 'System.ArgumentNullException' occurred in Microsoft.VisualBasic.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in LP_Wizard.exe
Any idea what wrong with that Microsoft.VisualBasic.dll in windows 7 and how i correct that problem ?
Thanks a lot for help .
If you want to pinpoint where the exceptions are occurring, you can select the Debug->Exceptions menu item, and in the dialog that appears, check the first checkbox for "Common Language Runtime Exceptions". This will make the debugger break as soon as an exception occurs instead of only breaking on unhandled exceptions.
This is also one reason why it is generally a bad idea to catch generic exceptions unless you are clearly logging the information caught.
What is happening is the debugger can "see" exceptions as soon as they are raised (hence the "first chance") before any catch block is hit. Any exception which is not handled by a catch block is considered a "second chance" exception and will break normally.
If these exceptions aren't stopping the running of your application because they are unhandled then you are probably OK. Most of the time the exception is handled by code and this isn't a problem. The output is simply Visual Studio letting you know the exceptions were raised.
See the "Avoiding first chance exception messages when the exception is safely handled" question for some methods to reduce this if there are too many to ignore.
Are your in the debugger? Are these exceptions your program is handling? If so you need to find a setting that tells VB to supress warning you of handled exceptions. Maybey this was set when installed on XP but not when you installed on W7. See if this helps:
http://www.helixoft.com/blog/archives/24
've been running through the MSDN help documents to get a hang of Visual Basic. After trying out the example using timers --one drags a label and timer component into the designer and adds the following to the components subroutine
Label1.Text = My.Computer.Clock.LocalTime.ToLongTimeString
The output for the immediate window during debug is the following
A first chance exception of type
'System.InvalidCastException' occured
in Microsoft.VisualBasic.dll
A first
chance exception of type
'System.InvalidCastException' occured
in Microsoft.VisualBasic.dll
The same error occurs on a previous MSDN example using a context menu component. Should I Try...Catch...Finally this error and try to move on? Or, am I dealing with something much more serious?
When you see something about a first chance exception, it only means that an exception was caught within the code you called but does not necessarily mean that the code failed. If the code runs without causing your program to crash and returns a valid value, then do not have a problem. You will also see output in the debug window about first chance exceptions when you implement your own try/catch blocks.
In the Debug menu -> Exceptions, you can enable the debugger to stop when an Exception is first thrown, even if it would be caught later; if you want to find out what's happening, this is the easiest way to do it
In the first chance exception examine the details of the exception. You should see a stack frame/trace property. In there you should see what line the error occurs on. This should help you.
In the IDE try going to Tools > Options > Projects and Solutions > VB Defaults and setting Option Strict to 'On' - this may help catch casting problems when you compile your project rather than when you run it.
A 'first chance execption' does not necessarily mean you have a problem in your code. It could mean the IDE or the compiler or any other involved component encountered and handled an error and in the process the debugger is notified and the exception is being reported to the immediate window. This is an excellent post on the topic:
http://blogs.msdn.com/davidklinems/archive/2005/07/12/438061.aspx
A quick and easy solution for debug and diag of First Chance Exception is :
AppDomain.CurrentDomain.FirstChanceException += CurrentDomainOnFirstChanceException;
and then
private void CurrentDomainOnFirstChanceException(object sender, FirstChanceExceptionEventArgs firstChanceExceptionEventArgs)
{
if (firstChanceExceptionEventArgs.Exception is NullReferenceException)
{
// do your handling and debugging :)
}
}
Multiple First Chance Exception during the runtime can cripple the performance of your application because exception handling is expensive. Especially in web apps. You can add this handler and look at specific first chance exceptions and try to avoid/correct them.