Throwing Exception To Get A Message Back To UI?

Feb 3, 2010

I have an asp.net application with separate classes for business logic and database interaction and then of course the UI. I am building a form to add a widget to a widget list table in the database. My UI collects the information and submits it to the business class. I'm going to write the business class to first double check that the widget has a name (I know I should do this in UI with validation, and I will, but this is just in case validation is forgotten) and if it does, go ahead and send the information to the database class. The database class will then attempt to write the info to the correct table using a try catch finally block. Any errors caught here are logged and then rethrown so I can inform the user. So, knowing that my database class may rethrow an error, my business class code will also be written in a try catch finally block.

So at this point I have a number of possible outcomes that I want to inform the user via the UI:

1) Everything was fine and the widget was added.

2) Something happened with the database write and the user should try again later.

3) The user forgot to name the widget.

My question is: should I write my UI in a try catch block and then throw a custom Exception with an Exception.Message in the business layer if anything goes wrong, or just have my business logic return a string that is the message? I'll want to know if the process was successful or not, because I'll want to format the actual message differently, so I'd have to use if...elseif to determine if the message was bad or not.

It seems like throwing a custom Exception in the business layer may be a good way to tell the UI something bad happened. If the UI doesn't catch anything then of course the operation was successful. Then again throwing an exception for missing data seems a bit hefty.

View 6 Replies


Similar Messages:

Throwing Exception Message Giving Internal Server Error HTTP Code 500 On Live Site

Oct 4, 2010

using vb.net/asp.net 2005

when a user enters a bad email I am doing a check on this and throwing an exception message as follows, this works fine on the test site but for some reason the same code on the live site gives a "internal server error" (http code 500). The code below:

[Code]....

not certain why this is happening, I assume that it's some server or config difference between the test and live sites. has anyone seen this before? For a quick fix i'm registering javascript alert and showing the same text so it works but I would like to figure out why the code above is not working.

View 1 Replies

What Is The Point Of Throwing An Exception

Apr 15, 2010

What is the point of throwing an exception? It it anyways going to be caught in the Global.asax Application_Error method.

Lets say in the following code we throw an exception.

try {
using (var dc = GetDataContext())
{
// We are doing some data inserts here.
}
catch ( Exception ex)
{
throw ex;
}

My Question: Even if we do not use try catch and throw here, any exception which will be raised here will be caught inside Application_Error method in Global.asax. Then what is the point of try, catch and throw in this case?

View 7 Replies

ToolkitScriptManager Throwing Exception On Calling Page_ClientValidate

Jan 17, 2011

I am using AjaxToolkit 4.0 which suggests to use ToolkitScriptManager in place of ScriptManager. But when I am using ToolkitScriptManager, it throws javascript exception when Page_ClientValidate() in called from javascript. However, this error is not coming when ScriptManager is used. Can anybody tell me how to make Page_ClientValidate() run when using ToolkitScriptManager?

View 1 Replies

C# - Send Method Of SMTP Is Always Throwing An Exception

Mar 25, 2011

The send method of SMTP is always throwing an exception. The message is : Failure sending mail Here is my code:

MailMessage mm = new MailMessage();
mm.To.Add("Yuvraj.dhot@xxxxx.co.in");
mm.From = new MailAddress("Kumar.Chaudhari@xxxxx.co.in");
mm.Subject = "Ant Subject";
mm.Body = "Body Cha MEssag here ";
SmtpClient ss = new SmtpClient("localhost");
ss.EnableSsl = false;
try
{
**ss.Send(mm);**
Result.Text = "Message Sent";
Result.ForeColor = System.Drawing.Color.Green;
}
catch (SmtpException ex)
{
Result.Text = "Message Not Sent :
" + ex.Message;
Result.ForeColor = System.Drawing.Color.Red;
}

I also tried using

ss.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;

Now it doesn't throw any exception, it executes fine but receiver does not receive any mail in his inbox. How can I fix this? Edit - This is the stack trace im getting.................

View 3 Replies

Security - Prevent Web Caching Throwing Exception?

Jan 18, 2011

I am trying to stop the caching of web pages using the following snippets in the ASP.NET however its not working and showing following error to me,

Response.CacheControl = "no-store";
Response.AddHeader("Pragma", "no-cache");
Response.Expires = -1;

[code]...

View 2 Replies

Padarn Web Server Project Throwing Exception?

Feb 14, 2011

I'm testing our OpenNetCF's Padarn Web Server.

In one of their Hands-On-Labs (HOL P101), an exception is being thrown at

private WebServer m_padarnServer = new WebServer();

The exception reads, "Exception in ConfigSectionHandler".

If you have experience with Padarn, have you received this exception before? If so, can you shed some light as to what I may do to debug this error?

View 1 Replies

System.Configuration.ConfigurationManager Throwing Exception?

Mar 17, 2011

I am having this strange case, at first time when the page loades, everything goes fine. But as soon as I click on any link which makes any ajax request, after that, I get this error while trying to read the configuration."System.Configuration.ConfigurationManager.ConnectionStrings' threw an exception of type 'System.Web.HttpException"I am using asp.net mvc 1.0

View 2 Replies

Throwing Exception When Field Is Zero And Clicking Edit Linkbutton

Mar 22, 2010

I have a radcombobox in radgrid nested inside FormTemplate:

Code:

<telerik:RadComboBox Skin="WebBlue" Width="250px" Height="150px" runat="server"
ID="TitleCombo" OnDataBound="Title_DataBound"
SelectedValue='<%# Bind("Title") %>' AppendDataBoundItems="true"
OnSelectedIndexChanged="Title_SelectedIndexChanged" AutoPostBack="true" />

then i insert an item to the top of list (at zero index):

Code:

protected void Title_DataBound(object sender, EventArgs e)
{
var item = (RadComboBox)sender;
item.Items.Insert(0, new RadComboBoxItem("Select title...", "0"));
}

It works perfect but, IF the Title field is zero and you Click EDIT LinkButton it throws an exception: Selection out of range Parameter name: value I would say that it's expected as zero index does not exist at the moment when i click edit button. I bind the combo from within RadGrid1_ItemCreated event.

View 21 Replies

HttpContext.Current.Session Is Throwing Exception In Business Class

Sep 8, 2010

In our application we have to access session objects in business class. We are using HttpContext.Current.Session to get the session value. In some cases it returns the value but mostly its throwing a null reference exception(Object reference not set to an instance of an object). We have the following code Try

If HttpContext.Current.Session("Username") IsNot Nothing then
' Statements to be executed
End If
Catch ex As Exception
'Log to db
End Try

Here HttpContext.Current.Session("Username") is mostly throwing an exception "Object reference not set to an instance of an object" While debugging we found that HttpContext.Current itself is nothing.

View 2 Replies

Site Went Down With Dictionary Throwing Index Outof Range Exception?

Jul 20, 2010

I have a static dictionary object which hold some Key and Value pairs in our site.We are getting Indexoutofrange exception some times and we couldn't figureout the problem why it is causing.This error is logged several times in the log file and site went down.Do you have any idea why this is happend?Please provide your advice ASAP as we are facing this issue in live server.

View 6 Replies

Forms Data Controls :: DataView Throwing Exception - Index Out Of Range

Jul 13, 2010

A dataview is throwing an out of range exception when a page submit button is clicked. The strange part is if you change the data in the dataview by selecting a different person in the DDL the page works fine. Its only when the page loads and the default person in the DDL is when the DataView throws the exception.

The exception is thrown on the last line when I add DV.Rows(0).Cells(1).Text to the id_num parameter. I know there is a value in the dataview because it is displayed on the page. I can refresh the dataview with another person's information and the code works fine. This really has me confused. Here is a bit of the code behind.

Dim dashDataSource
As
New
SqlDataSource()
dashDataSource.ConnectionString =
ConfigurationManager.ConnectionStrings("SSSConnectionString2").ToString()
dashDataSource.InsertCommandType =
SqlDataSourceCommandType.Text
dashDataSource.InsertCommand =
"INSERT INTO tblAcadReferrals(all columns and parameter info here)"
dashDataSourceInsertParameters.Add("id_num", DV.Rows(0).Cells(1).Text)

View 7 Replies

Web Forms :: Fileupload / When Deployed App On Server And Accessed It From Client System Its Not Throwing Exception?

Nov 3, 2010

I m uploading file to a directory inside my website root directory like this-

[Code]....

I m getting exception-

System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:Documents and SettingsAdminMy DocumentsVisual Studio 2008WebSitesElcomponics Sales-BDsamples&#65533;50841010_sd113201031833.pdf'.

Why so?

When i deployed my app on server and accessed it from client system. It is not throwing exception.What is the difference?

Still i want to confirm will it throw the same exception in case i deployed it to server and access it from client.

View 3 Replies

Web Forms :: Server.Transfer Throwing An Exception "error: Canot Obtain Value"?

Mar 1, 2010

I am using Server.Transfer("axpx page", True) in my page.aspx.vb code. This line of code is there in the Try block. The exception "error : canot obtain value" is occurred when this line is executed. This is started all of sudden in the production.I have temporarily fixed this by keeping this line after try - catch block. But I'm not sure why is this problem occurred?

View 8 Replies

AJAX :: Microsoft.Ajax Is Throwing Exception At Sys.UI.DomEvent.addHandler

Nov 17, 2010

I'm developing a asp.net website, i having a problem in one page i using ModalPopupExtender to show a asp:Panel, this panel have a updatePanel with e FormView and nested ListView and ataPager when this was done the Microsoft.Ajax js file throw exception"element is null or non object" at Sys.UI.DomEvent.addHandler.

View 1 Replies

Security :: Aspnet_regiis With The "-pa" Switch For "NTAUTHORITYNETWORK SERVICE" Throwing Exception 0x080070534

Mar 17, 2011

The environment:

Development:

Windows 7 64bit running microsoft visual studio to develop an ASP.NET web application in C#.

Production:

Windows Server 2003 : Microsoft.Net V3.5 : IIS

Application:ASP.NET web application with forms authentication using an Active Directory provider to authenticate against our domain controller. Once authenticated users can select reports which populate a gridview with data from an SQL database.

Background:The web app works flawlessly on development and production. Users can navigate to, authenticate, and access all information on the web app.

Due to sensitive connectionString and active directory provider information in my web.config file we have decided to encrypt those parts.

After researching different methods we chose to do a machine level RSA encryption.

The method which we are following in CMD:

1. cd c:windowsmicrosoft.netframework"version"

2. aspnet_regiis -pc "containerName" //this creates the key container

3. aspnet_regiis -pa "containerName" "NTAUTHORITYNETWORK SERVICE" //this creates an ACL for the NETWORK SERVICE user to be able to access the
container and decrypt the web.config file

4. aspnet_regiis -pef "connectionStrings" "C:inetpubwebsiterootdir" -prov "provider" (where provider is the name of the encryption provider in
web.config) //this uses the encryption provider to encrypt the data then storing the key in the container that we created in step 2.

5. Repeat this process for any other sections of web.config with sensitive info.

View 4 Replies

How To Create Our Own Exception Message

May 31, 2010

how can we create our own exception message ? for example i want to disply the message "Database Is not Connected" on the intrupption of database connectivity.

View 6 Replies

Pass Exception Message To Label On Another Page

May 3, 2013

I catch an exception, how can I use the exception message in another page? How can I pass this exception message into a label on another page? In order so I can have the exception message displayed with my own material. Catch ex As Exception ex.Message 'pass this message of the exception so it can be used in a different page.

View 10 Replies

Configuration :: Security Exception:ran Newly Built Msi/exe But Never Got Application Back ?

Jul 12, 2010

I'm having hard time to figure out whats going on with my IIS.My application was running in IIS very well untill I used Visual studio Copy website to update the files in the wwwroot.All of a sudden I got this error.My application works fine from the file system.I tried deleting my application from IIS and uninstalled from control panel and ran the newly built msi/exe but I never got my application back what so ever.This is web.config for reference.I've also tried <trust level="Full"> element but this didn't help.I remember the whole problem started when I was trying to debug the functionality to upload and download files in ASP.Net.

[Code]...

View 2 Replies

Global.asax File Not Giving Exception Message?

Sep 28, 2010

Here's my problem I have some code and I'm using it to send an e-mail with the last error details but all I want is the (Inner)Exception Message to be displayed in the email with the URL

Here's my code

[code]....

View 1 Replies

WCF / ASMX :: The Formatter Threw An Exception While Trying To Deserialize The Message

Sep 9, 2010

I have

[ServiceContract]
public interface IBusiness
{
[OperationContract][code]....

Add client: [Code]....

But......... the result

Error:The server encountered an error processing the request. The exception message is 'The formatter threw an exception while trying to deserialize the message: Error in deserializing body of request message for operation 'UpdateLanguage'. The token '"' was expected
but found '''.'. See server logs for more details. The exception stack trace is:

at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeRequest(Message message, Object[] parameters) at System.ServiceModel.Dispatcher.DemultiplexingDispatchMessageFormatter.DeserializeRequest(Message message, Object[] parameters) at System.ServiceModel.Dispatcher.UriTemplateDispatchFormatter.DeserializeRequest

View 1 Replies

Web Forms :: Passing A Message Back?

Jun 14, 2010

I've got a page (menu.aspx) that contain a ListView, within the ListView is a user control which is just a GridView of items related to those in the listview. Now the overall page is linked to a master page (Master.admin) that has a simple Literal control that I use to display messages, etc.

What I need to be able to do is if I update, delete, etc something from the Gridview (user control), I would like it to display what ever message I send to the Literal control

I can do it from the actual ListView itself by doing somethihg like ((Master_Admin) Master).Text +=
"My message";

View 2 Replies

C# - Dynamicdata Validation Exception Message Caught In JavaScript, Not DynamicValidator

Feb 12, 2010

I have a page here with a few list views on it that are all bound to Linq data sources and they seem to be working just fine.I want to add validation such that when a checkbox (IsVoid on the object) is checked, comments must be entered (VoidedComments on the object).

Here's the bound object's OnValidate method:

partial void OnValidate(ChangeAction action)
{
if (action == ChangeAction.Update) [code]....

Despite there being a dynamic validator on the page referencing the same ValidationGroup as the dynamic control, when the exception fires, it's caught in JavaScript and the debugger wants to break in. The message is never delivered to the UI as expected.

View 2 Replies

Web Forms :: How To Pass Exception Message To Custom Error Page

Apr 12, 2010

I am trying to passing Exception info tpa custom error page that I have created, and I'm looking for the best way to do so.I ended up creating a session object on my Global.asax page, and I pass the error data to the session object during the Application_Error event, but it throws it's own exception prior to working.

[Code]....

I have also updated my web.config with my error page that I would like to pass session object data to:

[Code]....

View 2 Replies

Way To Capture Unique Constraint Exception And Provide User-friendly Message

May 4, 2010

Using vb.net/asp.net 2005 and SQL Server 2005:I have a unique constraint setup to prevent users from entering duplicate email addresses in my online system.When a user tries to edit an existing email to one that already exists (add a duplicate) it shows the following<ERROR>Cannot insert duplicate key row in ojbect "dbo.someTableName" with unique index.....The statement has been terminated This prevents the user from adding duplicates which is good but I would like to provide a more user friendly exception message and I do not want to show the table and field names to the user.

View 4 Replies







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