.net - Handling Exceptions In A Class Library Enveloping A Device Driver
Sep 28, 2011
I am writing a class library that envelopes an USB device driver. This device has its own class library, provided by the hardware vendor.
Very often, especially if you handle with old DLL or COM assemblies, there are methods (functions to be correct) that return TRUE if all was OK, or FALSE if any error happen. Often these methods return information about the error in one of their parameters or separately in a GetLastError method or even if in an OnError event.
Now, normally I handle all native .NET exceptions in my class libray handling locally or re-throwing to the client if the error is useful to know. But what to do with all other errors that are hidden in the vendor's methods? (in the true I have no exceptions, but only returned TRUE or FALSE values).
Let's make an example with the method "CONNECT" that connect the client to the USB device.
I envelope the method in this way:
Public Sub Connect()
oVendorDevice.connect()
End Sub
now if any connection error happen, the vendor's connect method return FALSE. But I do not know why the connection failed. To know why the connection failed I have to call (for example) the method GetLastError that gives me information about the error. (but do not forget that other vendors use other strategies like returning the error in a method's parameter or in a OnError events.
Now, in order to follow a good .NET exception handling strategy I could write something like this:
Public Sub Connect()
Dim res As Boolean = oVendorDevice.connect()
If res = False Then
[Code].....
View 1 Replies
ADVERTISEMENT
Oct 21, 2009
So I've made this control that inherits from the treeview control and basically loads objects from active directory into a treeview (url...).All working fine, but as this is the first custom control I have made that I have intended for other people to use, I'm not quite sure how I should approach error handling.I mean, obviously I shouldnt do something like show any exceptions in a messagebox because that might not be what the person that is using the control wants to happen. So do I just write out exception messages to the debug window? Do I swallow exceptions (guessing not)? Do I just totally ignore them so that they are thrown in the user's project?
View 4 Replies
Jun 8, 2010
i created a Class library (.dll) and loaded it as reference into a main project. In the code for the class i've handled exceptions using try..catch subs, however when debugging the main project exceptions that are handled in the DLL still get thrown! (the class ".vb" file gets loaded into the debugger and the line of the exception shows up)
Up till now i've found it useful that when an unhandled error occurs in the imported reference, it shows up in the main project with tracing back to the referenced class. But i dont want the exceptions that are handled in the reference class to be thrown when debugging the main project!
As you can see the exception thrown was handled with try...catch this class exception.vb belongs to the project that created the class library (.DLL that i referenced). i didnt even load the project that built the reference so it amazes me that it could find the coding class to begin with.
View 3 Replies
Nov 13, 2009
A Problem in accessing a device from VB Windows cannot load the device driver for this hardware because there is a duplicate device already running in the system. (Code 42) This error is because i am using 2 devices of the same company which has the mass usb storage on it and when i install one of the device the other hides. So one is detected the Other is not. It also give a error called designed dragnonacally something...
View 2 Replies
Aug 13, 2009
I already read a lot about exception handling and saw many different threads on the subject but still confused when creating class libraries like the following scenario.
Lets say i have a class library "MyClass.dll", inside the project i have two classes:
Skeleton.vb
Imports System.IO
Public Class Skeleton
Public Function Create(ByVal resourceName As String) As String
[Code].....
View 4 Replies
Mar 11, 2012
I seem to recall that there is an API which will return the INF file associated with a device driver but I'm drawing a blank. I want to get the path to the INF File, File Name Section Name and File Date.
View 17 Replies
Mar 16, 2012
Is there an API which will tell you the start code for a device/device driver?
View 4 Replies
Mar 8, 2012
I am developing a software that will monitor/poll serveral Modbus/TCP devices on a network.
I have managed to connect to one device using VB.Does anyone know of a driver or perhaps a 3rd party software I could use that will enable me to connect to more than one Modbus/TCP device?
View 2 Replies
Jun 2, 2009
All of us use the try catch blocks. But what is the best way of handling errors within custom functions?Display a messagebox to the user when the exception is thrown (if possible within the function), or return a value indicating that an error was found within the function?
View 3 Replies
Apr 18, 2011
I have set up a process to create new tasks to handle file processing. A problem arised where I received and unhandled exception error and just clicking on the continue button, the main process continued to run. Now I also found that within the child task I was having a file conflict error and as the tasks run as separate .exe i was under the impression that everything would have been thread safe. So for the first issue here is the task creation in the main process..GProcess is a complete project on its own consisting of 6 classes. This is added as a class library reference to the main process class form1
Public Class Form1
..Private parser as GProcess.module = new GProcess.module()
dim factory as new taskfactory
[code].....
View 1 Replies
Aug 29, 2011
How does one handle unhandled exceptions in a DLL? VS doesn't give me the option to add Application Events, I'm guessing because it's a DLL. Do I just have to do it in the main app?
View 8 Replies
Sep 29, 2010
This was a difficult question to google. I have an Order class with a couple of dozen properties such as ClientReference, ShipMethod, etc. I use databinding to bind this class to an Order form. If a user enters an invalid shipping method, an exception is raised in the ShipMethod property and a validation error is displayed to the user. But I'm trying to use the same Order class within an OrderImport class whose job it is to take a flat file and create multiple orders. The problem occurs if I'm assigning to a dozen of the order fields consecutively, and say the first one causes a validation exception. If I have all dozen assignments occuring within a single try-catch block, the next 11 assignments will be skipped and I'll only be able to record one validation error. I could solve the problem by doing a dozen separate try-catch statements, but that doesn't seem very elegant.
View 22 Replies
May 21, 2010
What are some of the most common mistakes you've seen made when handling exceptions?It seems like exception handling can be one of the hardest things to learn how to do "right" in .Net. Especially considering the currently #1 ranked answer to Common programming mistakes for .NET developers to avoid? is related to exception handling.
View 14 Replies
Apr 28, 2012
When two computers are connected through TCP, and one of them closes and breaks the connection, it throws error 10054 "Remote host forcibly closed the connection".I want to handle this error because I know it will happen more often than not with the application I'm building. In System.Net.Sockets.SocketException, there is an on the error code. But when I run the program, the exception that is being thrown is System.IO.IOException, and the GetType for IOException is the socket exception. I don't know how to handle the socket exception if it's not the root cause of the exception.
Here is the code for my Try Catch block:
For infiniteCounter = 1 To 2
infiniteCounter = 1
[code].....
View 2 Replies
May 18, 2010
If any directory within a set being searched by the [URL] or [URL] methods contains a junction point, the entire method fails and returns zero results on my tests under VB 2008. I would like to make the call more robust: to return the folders or files not blocked by access restrictions and to note the folders which were blocked. Do those methods offer a means to do this, or is a recursive folder-by-folder call necessary?
View 3 Replies
Apr 2, 2011
I have an assembly containing a number of classes. This is a class library type assembly, not a windows forms application. It's also single threaded.Is there a way to catch all un-handled exceptions so that I can log them?
View 2 Replies
Nov 13, 2009
What is a driver module, and how would I add a class and get the driver module to read from the class.
View 2 Replies
Jun 21, 2011
I have a Visual Basic Class Library project. It generates a DLL. Is there a method to generate a static .LIB to which I can do a static link?Alternatively, can I do a static link against a DLL?
View 6 Replies
Dec 6, 2009
I'm creating a class library that contains a series of functions with Try...Catch blocks to handle errors. When i run another application that uses the class library, and call a function in the library using parameters that i know should cause an error (i.e. divide by zero), i don't get an exception thrown.
Can you not use Try.. Catch blocks in external libraries? If not, how are you suppose to handle errors in these functions?
View 6 Replies
Jun 1, 2011
Trying to figure out if there is anyway built into windows 7/Vista/XP and/or Dpinst to verify that a driver is installed? I created a program that uses DPinst to install a driver and now I need to figure out how to tell the user that it is safe to close the program once the driver is install as the driver takes longer on some machines to install. Would anyone know how to get this to work?
View 7 Replies
Feb 26, 2012
I created a custom collection class with some methods: each of these has some parameters and throws an exception if a parameter is not valid.For example, the Add and Remove methods throw an NullReferenceException if one of their parameters is null.[code]...The Replace method replaces an item in the collection with another specified object: to reach the goal, it first calls the Remove method and after the Add method. Obviously the Replace method could throw exceptions if at least one of the specified parameters is null, because Remove and Add methods could throw exceptions.Is this the right way to go? Or should I also check the parameters in the Replace method as in the following code? [code]...In fact, in this second case, each check would be executed twice: first in the Replace method and after in the Remove and Addmethods, which are called by Replace, and in other cases the checks may be rather expensive.
View 1 Replies
Nov 10, 2009
I'm currently working on a project where I am transmitting data from a comm device via the serial port and resorting the raw data (in binary) to its respective ascii values. The problem I'm facing is determining the most efficient method to accomplish my goal. Essentially, I have 68 bytes coming in, the first and second bytes represent the page and packet number and the data itself ranges from 3 to 64, the remaining for my checksum.
What I am needing to do is, grab 50 consecutive bytes per variable in my array, and that is where I'm confused. I have easily pulled my 3-64 bytes and stored that data to a string. I just don't know the most efficient method to accomplish my goal. Should I write directly to file all my data, as there are like 8 pages, of 128 packet data. [Code] I can capture the the first 50 by using a for-loop easily, but what would be the preferred method to track what data chunk I've taken? The more I think about it, I think I may just want to write to file, all my data, and then just take them back to back in 50 byte chunks. Is that the most efficient method?
View 3 Replies
Feb 14, 2012
I have a class library in VB.NET that does a NET-envelope for an USB device driver.There is only one function of that driver that I could not envelope in a traditional class, but I had to put it in a Windows Service as described here:Sharing a class property (field) between applications.The Windows Service works fine, but I have now two projects for my NET-envelope: the one with the class library, the second with the windows service and I do not like the idea to maintain two distinct projects for the same driver.Is it a good practice (or even if possible) to add a windows service class to a normal class library (without creating its own project as described in the vb tutorial)?I know, in any case I should create a separate setup only for the windows service, but in this way I could have together all the classes that envelope my usb device driver in only one project.
View 1 Replies
Sep 23, 2010
Part of my assignment is to check if input to Group Number and Number of Units are correct input by making error handling exceptions...
I have to check the following:
a) group number is neither 501 nor 062
b) number of units are NOT numbers
c) number of units is NOT a positive number
So my first question is, am I checking correctly? 2nd question is, How do I make sure my Exceptions will pertain to their correct respective things (a, b, and c.. above)?
[Code]...
View 6 Replies
May 18, 2010
I've createda vb.net class library where I've defined a number of small classes... nothing complicated, just working with strings, sending emails, etc.In another project, I reference the class library and I'm seemingly able to create an instance ofone of tclasses - intellisense shows me all of the plic properties, methods, etc... all looks perfect. No compile errors at all, nothing b gumdropsand lollipops.When I run the app I'm working on that references the class library, it fails at the point where I'm creating an instance of the class and gives me a vague exception, "System.TypeLoadException".
View 2 Replies
Mar 12, 2011
I'm posting this there is a relationship with my previous post [URL]
I have two projects, namely:
1. Project1 (Windows Application)
2. Project2 (Class Library)
in Project2 there are several classes:
* frmLogin.vb
* frmCustomer.vb
* clsGlobals.vb
in my case, I want to frmLogin.vb and frmCustomer.vb not called in Project1 and I can only call is clsGlobals.vb
View 8 Replies
Oct 19, 2011
I would like to catch any exceptions from any method in a class so that I may record class specific data to the exception for logging before it is passed up the stack. I know that I can put a try-catch in every method of the class, but there are many methods and It seems there should be a more efficient way. Example of what I am currently doing:
public class ClassA
{
private int x;
[code].....
View 2 Replies
Nov 17, 2009
I have made a class using New->Class Library. I have 2 constructors, 1 function (that computes length of circle), one subroutine that computes area of circle, and main subroutine.
Public Class Class1
Class Circle
Dim rad As Double
[CODE]...
My problem is when I try to run the program: No errors of syntax.
What I must do? I need to right click in solution explorer add new item->add->class and copy here this code?
After I write the code I chose from the vb menu: Build->Build Solution_name
Before writing the code I choose File->New->and selected class library then save all to save as a project.
Or class library is only a dll file that runs with a windows forms application. (that is added after i write the code for write library).
View 7 Replies
Dec 26, 2009
I've just skipped around a few inbuilt VB classes' methods which throws exception. of all that i've came across, methods may throw multiple exceptions but ALL of them are exclusive, meaning there is no way 2 exceptions will ever occur simultaneously, yea and i was trying to make my class throw 2 exceptions simultaneously, hence this question, must all exceptions be exclusive?
View 1 Replies
Dec 1, 2011
I have an event defined and firing in class B
Public myEvent()
In class A:
Private WithEvents _b as B
Private Sub hander() Handles _b.myEvent
but, this handler does not get called.
View 1 Replies