|
The answer to the question is always throw exceptions.
The only exception I can think of is some file handling situations where you can get an exception - but as previously mentioned the best thing to do is read up about it and use google.
As a general tip you should not handle exceptions as by handling an exception you are running the risk of corrupting any data in your system.
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
Tridip Bhattacharjee wrote: what is the best industry standard for exception management and error handling technique?
It depends on the situation.
An exception is supposed to represent an exceptional condition within the API that is being used. The caller is then responsible for determining what that exception means - to the caller.
Thus the caller can catch it and do something or not catch it all.
That is a general answer but it is further modified by what the caller is supposed to be doing. For example it is inappropriate to allow a SQL syntax error to bubble up to a UI to leave the consumer user to deal with it. But on the other hand one must tell the user that what they were trying to do didn't work. That means somewhere in the middle something must catch that exception, do something with it, and in some way relay a different error message to the user.
A common way of dealing with exceptions is to use a logging api and log it. Like everything that requires moderation and thought as well since one should probably also log other, non-exceptional information and also not log every exception because some are in fact expected (thus generally pointless to log.)
|
|
|
|
|
Well, not to mention what has already been said, but when I first started learning, I would just download OPEN SOURCE projects i could find on the internet, and just read their code. See how they figured things out and how they handled certain things throughout their application. After doing this to as many as 20 - 30 projects, I really started to get the feel of what is COMMON PLACE and what is not.
AS far as your question, i think you answered it yourself: Tridip Bhattacharjee wrote: i use those code in try {} catch {} block and show exception related message As that is what those are meant to be used for. The bigger question is "when should you use them?"
I Fart Ideas every day! It's just only once in a while one does not stink!
|
|
|
|
|
hi all,
i dont understand why memory of my application increasing here
i m just execution a for loop to check the datagridview have some values or not
int count=dataGridView2.Rows.Count - 1;
for (int g = 0; g < count; g++)
{
if (dataGridView2.Rows[g].Cells[1].Value != null)
{
}
}
please help me for this.
thanks.
|
|
|
|
|
How are you verifying that memory is increasing? What do you actually do in that missing line?
|
|
|
|
|
What makes you think it is?
What tells you the memory is increasing? How much?
And what is in the code section other than a comment:
Becasue that could be significant.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
in task manager the application increase memory continuously when i fill that datagridview.
and after some out of memory exception comes.
|
|
|
|
|
So you need to look at what the "missing code" is doing.
Because is the rows already exist, just checking on the content won't increase memory.
I know you aren't executing "just the code you showed us" in isolation: it's part of a bigger app.
So you need to look at what else is going on: any other threads, what the message stuff is doing, and such like.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
First of all, never use TaskManager to diagnose memory issues. It's not very good at it.
Secondly, without seeing what's going on in that missing section of code, it's impossible to know what's going wrong. The obvious suggestion is that you keep on filling something in there, which would suggest that it's an issue with your logic - i.e. you should probably be removing something in there as well. Beyond that, we cannot tell because you have given zero relevant code.
|
|
|
|
|
i use this
for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
{
Value = dataGridView1.Rows[i].Cells[sel_index + 2].Value.ToString();
if (dataGridView2.Rows[i].Cells[1].Value == null || dataGridView2.Rows[i].Cells[1].Value == string.Empty || dataGridView2.Rows[i].Cells[1].Value.ToString().Trim().Length == 0)
{
dataGridView2.Rows[i].Cells[1].Value = Value;
dataGridView2.Rows[i].Cells[1].Style.ForeColor = Color.Red;
}
else { }
}
|
|
|
|
|
There is nothing in that code that should cause an out of memory exception. I would suggest that the problem doesn't lie here, and that it's somewhere else. If you put a breakpoint in this code and step through it, you will probably find that it behaves as expected.
|
|
|
|
|
dataGridView2.Rows[i].Cells[1].Value.ToString().Trim().Length == 0
Value.ToString() creates a copy of "Value". .Trim() then creates a copy of that. If you have a lot of data in Value you have it x3.
If Value is type "object" but you know it contains a string then do a cast rather than ToString, and for checking if something is empty use string.IsNullOrWhiteSpace rather than a trim and length check.
string.IsNullOrWhiteSpace((string)dataGridView2.Rows[i].Cells[1].Value)
|
|
|
|
|
hello;
I have just started using VS2008 C# for windows mobile. I cannot make my label.text continuously display data, I verify the information is being passed but the form is not displaying the information. I tried this simple piece of code and it only displays the last value. please help.
namespace datatran
{
public partial class frmSend : Form
{
int i = 0;
int value;
public frmSend()
{
InitializeComponent();
}
private void btnSend_Click(object sender, EventArgs e)
{
value = Convert.ToInt16(txtBoxSend.Text);
while (i < value)
{
lblCount.Text = i.ToString();
lblCount.Show();
i++;
}
}
}
}
|
|
|
|
|
The reason why it's not working as you expect is that the thread executing your event handler method is also responsible for updating the screen - which it can't while it's executing the event handler method. Once it's done executing the event handler it updates the screen - once, and obviously with the last value that was assigned to the label text. One solution for this would be to employ a Timer (MSDN-Doc[^] / Codeproject Tutorial[^]) which provides you a simple way of changing the label text and updating the screen simultaneously.
I guess this was a desperate measure:
lblCount.Show(); - you don't need to do that each time you update the label text.
|
|
|
|
|
thanks for the idea on the timer, I tried it with the correct time interval but it still did not work. Not sure why.
|
|
|
|
|
The following code only updates the text with the current value of i through each step of the While Loop. So once the While loop is done, the text will of course be only the LAST value.
while (i < value)
{
lblCount.Text = i.ToString();
lblCount.Show();
i++;
}
If you are wanting the textbox to show each step through the While Loop, then try this:
lblCount.Text.Clear();
while (i < value)
{
lblCount.AppendText = i.ToString() + "\r\n";
i++;
}
|
|
|
|
|
thanks, but VS2008 do not support Append
|
|
|
|
|
I'm sorry, I just realized it is a label, not a textbox.
Not sure but this may work:
while (i < value)
{
lblCount.Text = lblCount.Text + i.ToString() + "<br/>";
i++;
}
|
|
|
|
|
|
Thanks all for the help, The answer to my issue is to use a text box instead. This works for me.
while (i < value)
{
textBox1.Text = i.ToString() + "\r\n";
i++;
}
|
|
|
|
|
that's a workaround. not a solution.
Not that, that's a bad thing, but it is important to note the difference.
|
|
|
|
|
It seems like it is looping through all the values and making the label display all of them. It is probably doing this so fast that you only see the last set value.
If you want to see all the values, maybe try lblCount.Text += i.ToString() + " " to display all the values side by side. If you do this, remember to clear out the label before looping.
|
|
|
|
|
thanks, I'm using the text boxes instead of labels.
|
|
|
|
|
Hello folks, I have a problem (as well as with the English language ^ __ ^) with a web service that I have already created and works fine. Now I have to add a header that contains an ssl certificate (.cer) but do not know how to do. Can anyone help? Place below the important part of the code. Thank you all!
BasicHttpBinding myBinding = new BasicHttpBinding();
myBinding.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.TransportWithMessageCredential;
myBinding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.Certificate;
Uri cUri = new Uri("https://Service?wsdl");//reserved data
EndpointAddress ea = new EndpointAddress(cUri);
CVPClient client = new CVPClient(myBinding, ea);
|
|
|
|
|
The method that has the following signature in the code bellow:
“protected virtual void SetProperty<T>(ref T item, T value, [CallerMember] string propertyName = null)”
What type of method is this. The body of the method is in the code in this post.
Thanks,
Truck
protected virtual void SetProperty<T>(ref T item, T value, [CallerMember] string propertyName = null)
{
if(!EqualityComparer<T>.Default.Equals(item, value))
{
item = value
OnNotifyPropertyChanged(propertyName);
}
}
|
|
|
|