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


ADVERTISEMENT

Forms :: Throwing Exceptions From A DLL

Sep 13, 2011

I have a application in which dll of another project added,

In my dll's I have several exceptions defined, and when specific errors occur

I throw these exceptions with the assumption that the main application will catch and handle them if the DLL does not.

but when any specific error occurs in dll main application cant able to catch it and whole aplication get closed. i have added an snapshot which appears when any error appears in dll

how do i handle the exception raise in dll from main project

View 1 Replies

.net - Why Have Equals Methods Have All Started Throwing Invalid Cast Exceptions

Mar 5, 2010

Several of my overriden Equals methods have started throwing Invalid Cast Exceptions -

Unable to cast object of type 'System.DBNull' to type Common.ResolveUser'.

This occurs when binding List (of T) (where T is of type ResolveUser in this case) to a combo.

Equals Method:

Public Overrides Function Equals(ByVal obj As Object) As Boolean
Dim i As ResolveUser = CType(obj, ResolveUser)
If i.UniqueResolveID = UniqueResolveID Then Return True

[Code]......

View 2 Replies

Option For User To Design Custom Reports

Dec 10, 2011

How can I give option to user to design there own reports? i.e. They should be able to define
1. Report Title
2. Reports Fields(When they click on Work Order button they should be able to view Work Order Table column and they should be able to select columns then a report should be composed. Then all the Column should be in the form datagrid. Is it possible.

View 10 Replies

Create An Error Message By Message Box To Tell The User To Enter A Number Only If They Key In A Character Value?

Feb 22, 2009

how to create an error message by message box to tell the user to enter a number only if they key in a character value?

I MEAN AFTER THEY PRESS THE CALCULATE BUTTON

Private Sub btnCalcFat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalcFat.Click
Dim intFat As Integer
intFat = Integer.Parse(txtFat.Text)
lblResultDisplay.Text = txtFat.Text * 9
End Sub

My text box is call txtFat

View 3 Replies

Asp.net - Display Specific Error Message On Custom Error Page

Sep 1, 2011

I know it's possible in asp.net to create a custom error page in a web app, by putting the following line in the web.config: <customErrors mode="RemoteOnly" defaultRedirect="frmErrorPage.aspx" />

I have had to do this for my web app, since it is clearly much tidier than letting the program bomb out with it's ugly default error page. My custom error page just has the customer's logo and a brief message saying "Error has occurred. Please return to homepage"The trouble now is that I have no way of knowing what caused the error, when a customer reports it.

Is there a way to make the actual error message appear on this custom error page too?

View 2 Replies

Asp.net - Custom Error Message In IIS

May 9, 2012

In IIS 5.1, i have set the website security to Basic Authentications and i have set the page for custom error in IIS which is directing to c:est.asp file. When user try to access the website, the user name and password screen comes up and after entering the wrong password 3 times, system shows the custom error page which is fine but why does system prompt for the user name and password again (for three times)?

I don't want user login screen on custom error page. I have tried to put the custom error page on the default website and set the security to anonymous but it still shows login screen on custom error page.

View 2 Replies

Asp.net - ServiceController.start() And ServiceController.stop() Are Throwing Exceptions?

Feb 22, 2011

The following code is throwing Exception. I don't get what mistake I am making in the code. i think it is of some security rights issue. If so, how can I give the security rights to any user or application to access this windows service programmatically?

Dim sc As New ServiceController
sc.ServiceName = "DataLoad"
If sc.Status = ServiceControllerStatus.Stopped Then

[code]....

View 1 Replies

Asp.net - Custom Validator Not Firing (No Error Message, But No Validation)?

Jan 17, 2011

I have a custom validator:

<asp:CustomValidator ID="QuestionValidator" runat="server" ErrorMessage="Please select an option" ClientValidationFunction="QuestionValidator_ServerValidate" OnServerValidate="QuestionValidator_ServerValidate" ValidateEmptyText="true"></asp:CustomValidator>

I have a list of questions provided by a datalist, which I need to ensure a user selects an answer to each question. I then have my validation functions:

Protected Sub QuestionValidator_ServerValidate(ByVal source As Object, ByVal args As ServerValidateEventArgs)
Dim SelectedItem As Boolean = False
For Each c As Control In Page.Master.FindControl("form1").Controls
If TypeOf c Is RadioButton Then

[code]....

When I run the page, there is no validation and no error message. Please can you point out where I am going wrong, I'm suspicious it is at Page.Master.FindControl("form1").Controls.I have previously done such validation by looping through controls via form1.controls but this is unavailable as the page uses a form passed down via the master page.

View 4 Replies

User Control Design Time Error

Apr 29, 2011

I'm trying to make a simple User control that houses one collection of a class that I've made. After building the control All works as planned and then randomly when I try to go to the design time interface for the form I placed the control on I get an error page with the following:

To Prevent Possible data loss before loading the designer, the following errors must be resolved:(ignore and continue: which about half the time works and the control shows up and the other part of the time all of the controls on the page are missing)

The one error is the following:Object of type'System.Collections.Generic.List'1[StaticGraphPlot.clsStaticCurveData]' cannot be converted to type System.Collections.Generic.List'1[StaticGraphPlot.clsStaticCurveData]'.

[Code]...

View 2 Replies

Error Message - Can't Load (or Register) Custom Control: 'comdlg32.ocx'

Jan 25, 2012

I'm trying to run a Visual Basic (4.0) program that has run on every flavor of Windows so far. Using Windows 7 I get the following error message:

Can't load (or register) custom control: 'comdlg32.ocx'

This file is in the same directories as it is in a WinXP machine where it runs just fine.

View 7 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 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

Generate An Error Message To The User To Let Them Know A File Doesn't Exist?

May 10, 2010

im trying to generate an error message to the user to let them know a file doesnt exist.So far ive got the user to enter the file name into a textbox, they click search and if successful will load a new form with a PDF file reader built in( AxAcroPDF1 )everytime i enter the right file name i get the file loaded, if enter the wrong name the File page still loads with no pdf and no message saying file doesnt exist.

Private
Sub PictureBox1_Click(ByVal
sender As System.Object,
ByVal e

[code]....

View 8 Replies

Returning A User Friendly Error Message To Client / From A Web Service

Oct 27, 2010

I need to return an error message to the client, if they have entered invalid data when calling my web service. So if my code is: [code]Is there a way to display a more user friendly error message (such as a message box or just the words "Invalid Order ID")?

View 2 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

Return An Error Message When The User Selects An Invalid File Path?

Apr 17, 2012

I'm using Microsoft Visual Basic 2008 Express Edition. I have a Folder Dialog Browser added in my form and I call it when the user presses a button. The folder path string is stored in a string variable and displayed as text in a text box. (maybe I should use a combo box)

My question is: If the user inputs by hand a non existent path, how do I return an error message, stop the file creation into the invalid path, and return to my main form?

View 1 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

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

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

Asp.net - .net Throwing Error To Parent

Feb 27, 2012

I have a question about how to properly deal with errors. I am working on a three tiered application. If an error is created on the data tier, I would like to pass the error to the business tier and process it there.What is the best method to accomplish this? I am using .net 2.0 and visual studio 2005.

View 1 Replies

Asp.net - Try-catch Block Still Be Throwing An Error?

Apr 23, 2010

Why would my try-catch block still be throwing an error when it's handled?[code].......

View 8 Replies

Converted Code From C# To .NET And Now It's Throwing An Error

Mar 4, 2012

Can someone please explain to me what this error means? I am new to VB programming and don't understand this. Error : Type 'var' is not defined

Here's my code

[Code]...

View 4 Replies

Null - If Block Throwing An Error

Mar 22, 2011

My code block is below. As it turns out, rdrCurrentRate.GetString(12) is a null value, but the code block throws an error. "Data is Null. This method or property cannot be called on Null values."My intention is to write "if rdrCurrentRate.GetString(12) is NOT NULL, then sCurrentRateType = rdrCurrentRate.GetString(12)"

What am I missing here?
If Not String.IsNullOrEmpty(rdrCurrentRate.GetString(12)) Then
sCurrentRateType = rdrCurrentRate.GetString(12)

[code].....

View 3 Replies

ODBC VB Throwing Syntax Error

Sep 7, 2010

I cant see what is wrong with my SQL statement syntax [code]...

ERROR [42000] [MySQL][ODBC 5.1 Driver][mysqld-5.1.41]You have an error in your SQL syntax;check the manual that corresponds to your MySQL server version for the right syntax to use near 'Int,Agi,Money) VALUES('MyUsername','MyPassword',0,0,0,0)' at line 1

View 1 Replies

System.Data.OleDb.OleDbException Was Unhandled By User Code ErrorCode=-2147217900 Message=Syntax Error In INSERT INTO Statement

Jul 8, 2011

I cannot seem to figure out why VB keep throwing me this exception but here is the code

[Code]...

View 3 Replies

Create A Message Box That Stores User Name, Message And Post Datetime Into The Database As Messages Are Sent?

Jan 6, 2010

create a message box that stores my user name, message, and post datetime into the database as messages are sent. Soon came to realise, what if the user changed his name? So I decided to use the user id (icn) to identify the message poster instead. However, my chunk of codes keep giving me the same error. Says that there are no rows in the dataset.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim name As String
Dim icn As String
Dim message As String

[code]....

View 7 Replies

.Net Examples Of User-Defined Exceptions?

May 22, 2011

example of a user-defined exception in VB.Net. I already have two examples that I was able to find online, but other than that, I cannot think of any more. I need to find at least 5 to put in my notes, and then submit to my teacher.The two I have so far are: invalid login information (such as improper username or password), and expired credit card information on an online store.

View 3 Replies

ExecuteNonQuery Not Throwing Error When Command Is Wrong

Oct 7, 2010

I'm passing in a sql command such as "EXEC StoredProc 0" into a a function called ExecMyCommand where StoredProc is a stored procedure taking a parameter of 1 or 0.It works fine with the following code.I had tried to judge success by looking at NumRowsAffected but soon realized that the -1 could represent a successful run even if -1 was the return value.So then I changed the code and return mLastRunOutcome = False if there is an error.So for testing I changed the name of the SP to like StoredProc2 in the database and ran the same command "EXEC StoredProc 0" and to my amazement, no errors were thrown in the code below..Of course ran the same command in Query Analyzer and it barked that there was no SP by that name.How do I know when a command ran successfully or not in code here? and Why didn't the ExecuteNonQuery throw an error when the command was not right??[code]

View 2 Replies

Stop A Program During Execution Any Other Way Than By Throwing An Error?

Aug 19, 2009

Is there a command that will stop the execution of my program?

I have a service that is processes an exchange account via telnet every 10 minutes. During one point of execution the application could possibly have a response from the telnet session when there are NO e-mails in the folder, which would look something like this[code]...

So is it possible for me to just stop my application at that point since there's no point in continuing if there are no e-mails in the account?

View 8 Replies







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