Vb.net Equivalent exception for Vb6 Error code - c#

Hi i am using the vb6 code Logic in my application where i need to manage the error handling. In vb6 ADODB.Errors are used for capturing the exception.
I want to know the exception equivalent in vb.net for the Vb6 ADODB.Error codes
2147217885 (0x80040e23) A given HROW referred to a hard- or soft-deleted row.
2147217887 0x80040e21 Errors occurred
Can anyone please help to know the equivalent exception for the above two error codes

Have a look at This,
in particular the section on "Unhandled Errors in Event Handlers". It explains how to use the ADODB Errors collection in a try/catch block.
I don't think you're going to find a way to trap ADODB errors by using equivalent errors thrown in the .Net environment. There aren't one-to-one equivalencies between COM errors and .Net exceptions in general. What happens in this case with ADODB Error objects is that .Net uses interop marshaling to throw the error object into the catch block, wrapping it with the Exception object. You can evaluate the error there. However, the doc doesn't explain how you can iterate the Errors collection to see both of your errors. Perhaps you can post how that's done here once you've figured it out.

Related

What does HRESULT 0x80040012 (OLE_E_NOSTORAGE) mean?

My Google-Fu has obediently told me that the following error
Not able to perform the operation because object is not given storage yet (Exception from HRESULT: 0x80040012 (OLE_E_NOSTORAGE))
which is being thrown from a C++ function called in a C# project is, in fact, an error which is related to OLE. But I can't find much more beyond that - what might cause such an error, or what functions would return it.
More baffling is the fact that although I know the code I'm using has spat out this error before, I personally haven't been able to reproduce it. It's coming from a pair of unit tests, so I doubt that I'm missing some vital step to reproduce the error, unless it's due to some arcane machine configuration. Can anyone help me understand where it might be coming from?

How to tell whitch exceptions a .NET call throws?

If one has the following code:
data.SaveChanges();
(data is an ObjectContext)
The MSDN doc has listed the OptimisticConcurrencyException as thrown. That's fine but I known that a UpdateException can also be thrown (and possibly others too). How can I know which exceptions a method can throw?
I do not want to catch Exception as I only want to catch exceptions which I know I can handle in some way.
This is generally speaking - not just for the example above. There must be some way of knowing which exception a 'built-in' .NET method is throwing.
That's not a "native" method; it's an ordinary method that happens to be written by Microsoft rather than you.
Actual native methods cannot throw managed exceptions (although COM interop will convert things to managed exceptions)
Unlike Java, C# does not have exception specifications, so there is no inherent way of knowing what exceptions a method will throw.
Your only options are the documentation or a decompiler.
Just in case (sorry if it's obvious but there're guys who don't know it) you can hover your mouse over the class name / method call in your editor view in VS. It shows you all the exceptions that can be thrown by the method if defined in documentation.

How to catch and save compile time and run time errors of my solution project in Visual Studio 2008/2010

I am currently trying to figure out a way on how I can possibly save the compile time and runtime errors (in database tables) that the project/solution/website in my visual studio solution explorer could possibly throw.
Thanks for the help in advance.
Update: For now I would want to log the errors only for C# language.
I am desperately looking for a way or solution to implement this...any help will be deeply appreciated...
NiK.
Compile time errors are saved in a html buildlog, check your output window for the link. Shouldn't be too hard to put in a database. A piece of software that does use this information is CruiseControl.Net, so you could probably learn from looking at their code.
For runtime errors, it's impossible to answer. First of all, it's unclear what you are asking. By "runtime errors", do you mean exception eg divide by zero? Second, this is also very different between different languages supported in VS, eg .NET languages and straight C++.
Update: Since you're on the .NET platform, I suggest you either wrap your main function with a try/catch block that catches all thrown errors, and just log all the information you can get from that error to your database (eg stack trace, Exception kind, perhaps a minidump). This, of course, will not work with errors that are caught or swallowed. In case you would also want to log those (for whatever reason), you would have to do some more clever source transformations, for example by using reflection. An example would be to add logging to the constructor of the base class Exception.
My suggestion would be to look into developing an extension to visual studio, similar to Jetbrain's Resharper. Visual Studio exposes a rich api for interacting with the IDE itself. If you are using command line builds outside of visual studio, you may need to pipe the output to a file and parse it.
Here's a few links to get you started on developing an extension/add-in:
http://msdn.microsoft.com/en-us/library/dd885119.aspx
http://msdn.microsoft.com/en-us/vstudio/bb968855
And here's a link for a video for integrating with the error list:
http://msdn.microsoft.com/en-us/vstudio/cc563922
Runtime errors may be easier since there is an appdomain exception event that you can handle. You can wire up a handler to this event and log the exception.
http://msdn.microsoft.com/en-us/library/system.appdomain.unhandledexception.aspx
For handled exceptions, there are a couple of techniques. Microsoft has an exception handling block that can be used, or you could create a custom exception type that you use throughout the application.
Sound like you want this for a website. You can create a Global class (Global.asax.vb) and then handle the error in the Application_Error event. This is where you deal with any unhandled exceptions (vb example is what I have):
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
' Fires when an error occurs
Dim appException As System.Exception = Server.GetLastError()
Dim tempException As System.Exception = Nothing
If appException Is Nothing Then
Return
End If
tempException = appException.InnerException
tempException will hold the unhandled exception and you can store it in a database, or email it to someone. Your choice.
You can do something very similar in winform apps by handling the _unhandledException event in the Application events.
Visual Studio Project files are MSBuild files which can contain custom compilation steps. Maybe it's possible to replace the compilation step with a custom step which calls the CSharp compiler and logs the error.
If you give us a bit more information on what you want to use it for, maybe we can provide alternative solutions. For example do you need to log the errors from inside visual studio or is it enough to have an external tool log these errors?
Only the C++ compiler does a buildlog. C# does not. You will have to either go the plugin/extension route (in which case, use Dave Ferguson's suggestions to get started) or you can use the command line to compile (csc.exe) and pipe the output to a file (csc.exe /options >> log.txt), and parse it.

Error details in embedded IronPython

I'm executing IronPython in my application. A script produces an UnboundNameException with the message "name 'source' is not defined". Because the script is correct in my opinion I would need more error information, but I'm not able to get them from the exception. The exception itself seems not to contain any information about line number of the source of the exception or something like this.
I searched on Google, but all available information seems to be outdated. The Data dictionary of my exception is empty which means that Data["PythonExceptionInfo"] does not exist.
The file version of my IronPython assembly is 2.0.20209.0
Any hint how to get more error details?
cheers,
Achim
See this question: Getting traceback information from IronPython exceptions
That will tell you how you can format the exception (and in a general way that's not going to become outdated). That should work w/ IronPython 2.0 - 2.7.

Handling custom .Net exceptions in COM+ (VB)?

I'm about to start writing a .Net component which will be called from a VB COM+ service (the new component is a DLL which calls out to a webservice and returns based on the response). I'm not sure how to handle error conditions that might occur in the .Net code in the calling VB.
The two types of errors I'm worried about are:
exceptions that I might like to throw if a precondition is not met (e.g. the start date supplied as a parameter is less than 3 months after the end date supplied as a parameter; I might want to throw a StartDateNotValidException)
exceptions that are likely to happen as part of the webservice call (time out, 404 etc).
I'd like to return some specific feedback to the user and/or log some information to a log if either of these occur. I'd thought about returning Int return codes from the .Net code and avoiding Exceptions, but it's possible that the calling VB code may eventually be migrated to .Net, so I'd like to use Exceptions if possible.
I read on MSDN that COM Interop will automatically convert standard library exceptions to HRESULTs; has anyone had any experience using this? Could this be used to translate custom .Net exceptions to error conditions that I can handle in VB?
Thanks,
Nick
I am sure I have seen it done before, but it was in my previous job so I can't check the details. I think we inherited our exception classes from COMException and set the correct ErrorCode (which should be translated as HResult in unmanaged code). This is quite nice, because you can use HResult in unmanaged code as well as properly handle typed exception in managed client.
Please let me know if it actually works.
I ended up using the following method:
have a big Dictionary
that maps our application-specific
VB error codes to our
application-specific C# custom
exceptions
write a method that converts C# exceptions to VB error codes (and
vice-versa)
return an array of strings from the methods containing any business
exceptions that occurred in the
method call (there are only currently two of these)
The reason for doing this is that it was going to be too cumbersome to adapt our exception tree to extend COMException (more cumbersome than the above anyways). So, I never tried out inheriting from COMException and checking whether the ErrorCode got correctly converted to an HResult.
Thanks for the suggestion though, and apologies for not trying it out.

Categories