VS 2008 Handling Exceptions In Custom Control Library

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


ADVERTISEMENT

.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

Handling Exceptions Within Custom Functions

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

VS 2008 Handling Exceptions In Referenced Class Libraries

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

Calling DoEvents From Inside Custom Control Library

Sep 21, 2010

I have a custom control's library. Now there's a control which looks like a panel, and when it opens up I want to animate its vertical growing like this:

For h As Single = 0 To finalHeight Step 0.5
Me.Height = CInt(h)
' HERE I WANT TO CALL DoEvents'
Next
Me.Height = finalHeight

If I don't call DoEvents in the loop then the animation is not shown, I only get the final height without a visual feedback along the way. I can call DoEvents from inside my main WinForm project, but can't inside a library. How can I do that, without drowning into the deep threads waters?

View 6 Replies

Handling Task Factory Exceptions?

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

VS 2010 : Handling Unhandled Exceptions In A DLL?

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

Assigning Consecutive Properties While Handling Exceptions?

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

C# - Common Programming Mistakes In .Net When Handling Exceptions?

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

Handling Exceptions With A Specific Error Code Condition?

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

Handling Unauthorized-access Exceptions When Searching Folders

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

VS 2008 Custom Dialog In A Class Library?

Mar 3, 2010

It's been a while since I last posted something, but this attracted my attention. Since many of my programs share the same type of code, I decided to dump it all in a class library for other programs to use.

Now I have a problem, Windows Forms in a class library can't be displayed. There is no "Show(Dialog)" command, only some for event handling. All properties are gone as well. The only way I managed to display a form is by making it as a new variable: 'Dim f as windows.forms.form

But this won't work because of the enormous amount of handlers added to the original.

How can I show my (TextureBrowse in my case) Dialog so other programs can use it?

View 9 Replies

Catch All Un-handled Exceptions In A .net Assembly (library Type, Not Application)?

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

How To Throw Custom Exceptions

Sep 24, 2011

I am catching sql exception from databse as shown below.[code]Now I want to throw exception by adding some userfiendly information,Like below.Throw SQLexception + "my message.....".

View 8 Replies

Handling Exception On A Class Library?

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

How To Catch Unhandled Exceptions In Custom Controls

Jan 5, 2012

Is there anything similar to the MyApplication_UnhandledException for an user control in VB?
I would like to have a central point where to catch all unhandled exceptions of a user control, without propagating the exception to the application that uses the user control. I made some test raising an exception in a method of my user control where there is no try/catch code (of course in the true project all methods have a try/catch block). The exception was caught by MyApplication_UnhandledException event of the application using the user control. But this is too "far" from the point where the exception happens and in worst case the user should restart the application.

I would like to realize a behaviour for the user control in order that if the user control fails, the exception is not propagated till the application, but just caught at user control level.

View 2 Replies

Create Custom Exceptions To Inherit From System.Exception?

Jan 16, 2010

Is the only way to create custom exceptions to inherit from System.Exception?

I wish to create a class that can be thrown as an exception but i do not wish to inherit from System.Exception because i have a base [Object] class in my library which all my classes should inherit from and i wish my custom exception class could also inherit from it.

View 6 Replies

Throw System.Exceptions From Within Custom Classes To Calling Code

Jul 9, 2010

I Have just been watching a video on throwing Exceptions. Are you supposed to throw System.Exceptions from within your custom classes. to the calling code, Which other way can they communicate. I have read in several places it is bad practice to throw SystemExeptions.

View 3 Replies

Throwing Exceptions For User ? Or Better To Design Custom Error Message Framework?

Nov 10, 2010

I never got into detailed error processing too much when I played in VBA/VB6 a lot. Mostly then, if you ran into a user error (such as some input of theirs failing a validation test of some kind), you popped a MsgBox() with some error information and the critical (or warning) icon, and safely aborted out of the code

In .NET, my reading basically points to exceptions as the end-all in error handling. It looks to me that if you know a spot of code where a user can screw up, you're supposed to catch it with either try...catch blocks (for things like data conversions), or standard if...the...else constructs for other things, and then throw a new exception if needed.

Isn't throwing an exception essentially a forced crash of a program in a sense (granted, you get the option of continuing)? Or are exceptions geared specifically for things like data conversion errors and other "things that shouldn't happen", and resume use of MsgBox() and friends for minor user screwups?

Consider the case of where you have a TextBox that is only supposed to accept numeric data (or heck, just a specific set of characters). Barring some other trick that lets you restrict that field (let's just assume it's freeform, programatically), it would seem a bit of a waste to throw new exceptions everytime they type in an invalid character, or even if the error checking doesn't happen until they press a submit button (like on a webpage). Popping a MsgBox() seems more sane in that case.

So what's the straight dope on exceptions and throwing new ones on user errors? How about if your program also exposes a programmatic framework? Bad usage of one of the programmatic functions definitely seems like new exception territory to me.

View 1 Replies

Use Custom Error Handling?

Mar 8, 2010

When debugging a program, instead of doing this on EVERY piece of code:

Try
MyFunction()
Catch ex as Exception
MsgBox(ex.Message)
End Try

Is there a way to apply that to everything error I encounter without writing it on every function/sub/etc?

View 3 Replies

Check If Input To Group Number And Number Of Units Are Correct Input By Making Error Handling Exceptions

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

Handling Focus With Custom Controls?

Nov 3, 2011

I have a custom control I'm creating. When I click on it, it draws a dotted border and puts some nubs on it for resizing. This all works perfectly. Now I want it so when I click off of it, it deselects. I already have a variable to set up if it's selected or not and subs to draw/clear it. I just have to be able to detect when something else is selected or it gets clicked off of.

What I've Tried

My first and best solution to this was to use the LostFocus event, but, by custom control apparently won't let it fire. After some research, as far as I know, custom controls don't have Focus events because they are custom and could be changed (basically, you have to implement the focus events yourself).

My Question

Does anybody have a solution to either implement the focus events or a way to handle off clicking for custom controls?

Sources

Here is my controls current source:

Imports System.Drawing.Drawing2D
Public Class wDOMElement
Inherits Control

[Code]....

View 1 Replies

Form Is Not Handling The Event Of A Custom Class?

Jul 24, 2010

I have a custom class which basically manages the program settings.

In it's New() event, I'm performing a check to see whether a value stored in My.Settings is the same as the default value (I made sure the value wasn't!), if not then it will perform a RaiseEvent ValueChanged().

On my form, I have an instance of the class declared "Private Withevents ProgramSettings as New clsProgramSettings", I also have a handler "Private Sub DoSomething() Handles ProgramSettings.ValueChanged" declared.

When I run the program the form gets loaded, the instance is created, the RaiseEvent is called, but the handler is not receiving the event?

I tried "Private Withevents ProgramSettings as clsProgramSettings", then creating the instance in the Form.Load(), but still no success!?

Is there something I'm doing wrong, or is there a problem with the IDE? I'm using VS 2010.

View 2 Replies

VS 2008 Custom Control?

Oct 4, 2011

I've not really worked with them before, well at all really. How would I go about creating a control which has multiple picture boxes, so then I can access each picturebox and refer to them via custom properties? I'm not aware you can draw several picture boxes and combine them into one control?

View 2 Replies

Serialization Fails Because A Form Is Handling A Custom Object's Event

Aug 12, 2009

My application's binary serialization was working well up to today (this is not a released app yet - still in development). I have a "Project" class that is the top-level class of a hierarchy of other classes related to its function. And before you think it, yes, all of those classes are marked as serializable. Infact, they all were being serialized before today.

I have one event on the Project class that assists in informing when the project's save status has changed (i.e. new, modified, saved). This event was added today along with some events on the other classes that filter up to the Project class (the project needs to be told when its objects have been modified). I unfortunately added all of this at the same time so I can't provide any incremental details as to when it stopped working, but when I try to save the project through my binary formatter it tells me that my main form is not marked as serializable. Well, yeah... of course it isn't! it shouldn't need to be because there is no member of my classes that even mentions the form. But for some reason handling the Project's event on the form triggers this error.

Serializing the form is not a solution. Neither is not being able to handle my Project events. If I comment out the handler it works fine -- and I don't even have to remove the WithEvents keyword on my form's Project variable. Now that I write that I'm speculating that it may have to do with the event being raised as a result of the serialization (occurs when the save button is clicked).

View 7 Replies

VS 2008 Add Custom Control To Form?

Apr 15, 2009

this forum, I made a custom numeric TextBox that was designed to accept monetary input.

vb.net
Public Class moneyTextBox

[code].....

View 2 Replies

VS 2008 Custom Control Dll Reference?

Sep 11, 2009

In THIS Thread:NickThissen Said:Quote:It will appear in the toolbox even if you put it in the current project, instead of a control library project.No, it does not have to be in a control library, nor does it have to be a UserControl, to appear in the Toolbox. Any class inheriting (either directly or indirectly) from Control or Component will appear in the Toolbox. Since RadioButton inherits from Control, and your control inherits from RadioButton, your control inherits from Control too, so it will appear in the Toolbox. I have successfully created a pretty cool custom control. I Built the project and have added the a reference to the .dll form a new Windows forms project. It works great, as long as I do something like THIS:

Dim ThisControl As New MyCustomControl
ThisControl.Top = 40
ThisCOntrol.Left = 40

[code]....

View 3 Replies

VS 2008 Custom Control Enhancement?

Mar 8, 2010

I have the above control I am using, whose base class is the ListBox.Unlike the ListBox, it doesn't highlight a new item when it is inserted.I already had to add the ability to InsertAt() a new item since the person who made it originally hadn't implemented that part.But, I am having trouble figuring out how to make that part work.The above link is directly to the original Control.Here is the code for the Insert method I added:

Public Sub Insert(ByVal index As Integer, ByVal value As MCListBoxItem)
Try
List.Insert(index, value)

[code].....

View 5 Replies

VS 2008 Custom Control Refresh

Jan 27, 2010

I have several custom controls inside my project, just added a new class and then inherit the original control. For example i have a Custom DataGridView Control (CustDGV), that defines several properties in the constructor of the control.Now i have one problem and one issue, the problem, if i change the CustDGV i don't know why, the forms that are using the control doesn't update the changes... The only way it's removing and adding it again.. not very useful when i have several event's already defined for the dgv.How do i force the form to update the control?The issue it's that some of the properties doesn't get applied, for example i set the column header height and the disable resizing in the constructor, but if i run the code this two properties doesn't get applied, i need to define them in the form where i use the control to get the results that i expect..The order of the properties in the constructor? The properties in the properties window override the constructor ones?

View 17 Replies

VS 2008 Debugging The Custom Control?

Jan 5, 2012

I have a custom control I've created, and I'd like to be able to step through it (either in a test application or the one it's being used in). Is there a way to do this?

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved