|
I recently started wrting C# and I was curious to know what was the difference between validators and exception statements. I was wondering when and why use a Try...Throw statement as in contrast to a field/control validator. Don't both these feature do the same thing? Ensure that the correct variables are being inputted into the application. This is why the question the begs to be answered is when do u use a validator and when do u use a try..throw exception?
Greg
The Belizean Dan Dada!!!
|
|
|
|
|
I personally use try/throw when making a call to the SQL server. I have a program that inserts into a database. If the insert fails, then I use the catch to dump an error message.
When using plain old vanilla fields validators work just fine.
I don't know if one has more overhead that the other; that may be a consideration as well.
|
|
|
|
|
Hello
Exceptions were neatly described by a known programmer as "Expecting the unexpected" -unfortunately I don't seem to remember his name at the moment-.
The more your code is advanced or complicated, or doing hardware related tasks for example, the more error brone your code gets. Sometimes you write a long method to calculate some value, and in the middle you find yourself dividing by zero- for example-. Or accessing an access denied resource, unexpectedly deleted file, wrong or unavailable adress, etc...
Examples of exceptions are by far more than what a simple post can count. There are literallt thousands of cases in which you can benefit from putting your code in a try block. Yet that will be at the cost of excuting time. The more try block, the slower your program gets. While a simple validation methods only handles the user input.
The throw statement is appropriate when you want to put the error handling on the shoulder of a lower method in the call stack. ie. You don't want to handle the code in the current method, instead throw it back to the calling code.
To summerize:
Validation is concerned mainly with user input, to save the time that would be consumed by exception catching. While in other situation when you don't know what might go wrong -yet sometimes you might expect, or have a kind of an idea-, then it would be wise to put your code in a try block to prevent your program from crashing.
Regards
|
|
|
|
|
This makes a whole lot of sense. In essence a try...throw would be best used for a derived value while validators are use to ensure that those braineless users can not input flakey data.
Greg
The Belizean Dan Dada!!!
|
|
|
|
|
Hello development community, I have a communication problem with two applications (client & server) I'm developing. The frase is "event notification". I have a client application that connects to a server application to subscribe to an event, for example, my server app. has a list of sales being made through out the day, so it's constantly recievine data from the sellers, and supose the client app. wants to be notified when a certain sale from a certain seller is made, so the client could be waiting for a few minutes until the data is available on the server and can be notified.
But wait there's more, there's a high probability the client is behind a firewall and in a private network, I don't know if the solution is affected by this.
Maybe this example is absurd, but my application needs to do something like this. Like MSN Messenger, you connect and wait for a friend to send you something. In my case they aren't string messages, they're objects from the buissnes model. I need to know how to do it, what do I need and a little orientation on using or mixing the tools.
I've been reading books on .NET Remoting, Web Services and Sockets, in search for an answer, but haven't been succesfull.
Maybe its simple and it just hasn't hit me or maybe it is a little elaborate to do.
Thank you.
|
|
|
|
|
Client registers to your webservice indicating that it would like to revieve event notification.
Your application will then call a webservice on the clients end when that event occurs.
It would be fairly trivial to implement.
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
Ing. Pedro Fernandez wrote: the client is behind a firewall and in a private network, I don't know if the solution is affected by this.
A firewall can affect anything you want. A typical implementation of a firewall would normally block the servers attempt to connect to the client that is behind the firewall as in the Web Service approach that Ennis suggested.
Using a nailed up connection over port 80 would be about the only way to accomplish this thru a typical firewall configuration and even with that the admin could still block your servers domain.
"Just about every question you've asked over the last 3-4 days has been "urgent". Perhaps a little planning would be helpful?" Colin Angus Mackay in the C# forum
led mike
|
|
|
|
|
Hi everybody
i am going to develop a telephone system project or it seems to me like that
the problem is:
we allready have something like a switch but the problem is that switch maximum have five ports only we want to develop a desktop program that we just buy one telephone line from the telecomunication company and seperate this one line to more than five telephone cabin that can used in the same time and count the time the call take in order to count the many that the calls cost.
my Q. is is this available in C# or any other language to deal with that and how ?
thank you for helping me
yours
|
|
|
|
|
And some $300 hardware.
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
a computrized system that control the telephone ?
|
|
|
|
|
Can you do it with the existing phone system you have? No, I seriously doubt it. Do you homework on how the phone systems REALLY work, then you can start thinking about this project.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hello ystar,
Do u hear about Asterisk open-source PBX(Click Here). Which can provide u a complete telephone exchage & also comunicate with telephone line.
But to connect with telephone line u have to purchase FXO card or other hardware that supported by asterisk.
Asterisk is only for Linux. U can make soft phone or just purchase it. And if u want to use existing telephone then u have to purchase Cisco Linksys hardware(Find Here).
Now by using Astrisk u can controll all things by ur computer.
regards,
Divyang Mithaiwala
System Engineer & Software Developer
|
|
|
|
|
A co-worker of mine is having trouble with his C#. Unfortunately, I don't deal with C# all too much so I'm not entirely sure where the error is taking place.
He's having trouble with a line of code used to create a Crystal Report. He's trying to call the .ExportOptions property of the ReportClass object, however for some reason, visual studio isn't even providing the dropdown to access the different ReportClass properties. It's not recognizing repClass as a ReportClass variable. Any idea why?
-------------------------------------------------------------------
public partial class _Default : System.Web.UI.Page
{
private static Data_PSPP oData_PSPP;
private string sID = "";
private ReportClass repClass = new ReportClass();
protected void Page_Load(object sender, EventArgs e)
{
DataTable dtSource = new DataTable();
oData_PSPP = new Data_PSPP();
this.sID = Session["ProjectID"].ToString();
if (!IsPostBack)
{
ExportOptions objExportOptions = new ExportOptions();
DiskFileDestinationOptions objDiskFileDestinationOpions = new DiskFileDestinationOptions();
string ExportFileName = "";
//Problem line.... "repClass" doesn't provide access to ".ExportOptions"
///////////////////////////////////////////////////////////////
objExportOptions = repClass.ExportOptions
//////////////////////////////////////////////////////////////
}
}
}
-----------------------------------------------------------
Thanks in advance.
-Goalie35
|
|
|
|
|
So, what exactly is the problem? Is the problem that IntelliSense isn't working? Is that all? Are you Is your colleague getting a compiler error?
:josh:
My WPF Blog[^]
|
|
|
|
|
He's getting a compiler error because for some reason, vs.net doesn't feel ".ExportOptions" is a valid property of ReportClass. Or at least a valid propery of the variable assigned the value of a ReportClass(the "repClass" variable)
This same code was implemented in VB.net and we had no problem, so it's a little odd.
Thanks again.
-Goalie35
|
|
|
|
|
Goalie35 wrote: He's getting a compiler error because for some reason
What does the compiler error say? What is the actual error message?
:josh:
My WPF Blog[^]
|
|
|
|
|
Hi,
The problem is that the reference for ReportClass is not set. For further info check
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/aspnetcustrep.asp
|
|
|
|
|
hi i m reading images from the databse and showing on picbox,so i had to make the temporary file to show pic on the picturebox thorugh Pic.image=Image.fromfile etc. it works fine.
i want to make one file for that purpose and delete when new file is readed from databse.
i m using this code for that purpose
Pic.image=null;
if(File.Exist("temp.bmp"))
File.Delete("temp.bmp");//give exception file used by process
String newf="temp.bmp"; and save the new data from database to this file and show it to the user.
but it give the exception that file is used by another process,i had clear the picbox but still gives.
how to do that Thanks in advance.
Tasleem Arif
|
|
|
|
|
Cross posting is considered very rude!
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Dave Kreskowiak wrote: Cross posting is considered very rude!
Looking at some of his other posts, he seems to do it often.
|
|
|
|
|
How to add for example all Columns from DataTable or DataSet into control`s (DataGrid) Collection drop down list.
For example I have DataTable and DataGrid, I connect those two and in Collection , each item in collection has few properties one of them is "Column" property, now when i want to chose witch Column I want, all columns should be displayed in drop down list (trought UITypeEditor), but problem is how to do it ? How to pass column names to item(s) ?!
My English is bad i know
Thanks
|
|
|
|
|
We have a Windows application that was built in VS 2003 and .Net 1.1 - we just upgraded everything to VS 2005 and .NET 2.0.
We ran some upgrade installations recently and at the end of the installation process got a System.BadImageFormatException error. it doesn't happen all the time but at least 50%.
We do have a couple of launch conditions and custom actions in our deployment but nothing that i can see would be causing this necessarily.
Any ideas?
Thanks,
Eric
|
|
|
|
|
to add to my first post...we have an installer class that runs first during the installation. The full error was:
Exception occurred while initializing the installation: System.BadImageFormatException: The format of the file "Installer.exe" is invalid.
|
|
|
|
|
Hi everybody,
i need to know how to step through FOP Source code as it gets executed. If anybody can help that would be great.
Thank you in advance.
He who laughs last...
|
|
|
|
|
"FOP"?? Fraternal Order of Police??
You might want to elaborate on this and what you're really doing with it, besides trying to debug it.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|