|
Hi Michael,
Michael Sync wrote:
int Eaten = 0;
try
{
throw new EncodingException("this is encoding exception");
}
catch (EncodingException ex)
...
} Are you staing that the exception can only be caught in the function that generates it? I have read explicitly otherwise. The CLR is suppose to walk the stack looking for a handler. According to Richter:Another advantage of exceptions is that they do not have to be caught or detected in the place they occur; any code in the thread's call stack can handle a thrown exception.
Jeff
[1] CLR via C#, p. 421, ISBN 9-7807-3562-1633.
|
|
|
|
|
Jeffrey Walton wrote: Are you staing that the exception can only be caught in the function that generates it?
No. This is just a sample.. What I mean is that you have to throw this exception if you wanna get the custom exception...
The following code works too..
private int MyMethod(){<br />
throw new EncodingException("this is encoding exception"); <br />
}<br />
int Eaten = 0;<br />
try<br />
{<br />
Eaten = MyMethod();<br />
}
catch (EncodingException ex)
...
}
You didn't show us what you wrote in your function TryParseNested . If you don't throws your custom exception then this exp won't be caught.
Thanks and Regards,
Michael Sync ( Blog: http://michaelsync.net)
"Please vote to let me (and others) know if this answer helped you or not. A 5 vote tells people that your question has been answered successfully and that I've pitched it at just the right level. Thanks."
|
|
|
|
|
This would be a joke if I did not spend 5 hours working on this one issue. Everyday, one problem with this language consumes the majority of my time. TreeViews, Splitters, Exceptions. It never ends.
|
|
|
|
|
What is your interest?? If you are not very interested about programming, you should not probably learn about this.. I've seem a lot of people (esp: students) are learning about programming even they are not so sure whether they are really interested or not.. don't tell me that my dad forced me to attend this school even you don't wanna attend.. programming is NOT for every body.. Every body can't be a software engineer, programmer or developer...
Thanks and Regards,
Michael Sync ( Blog: http://michaelsync.net)
"Please vote to let me (and others) know if this answer helped you or not. A 5 vote tells people that your question has been answered successfully and that I've pitched it at just the right level. Thanks."
|
|
|
|
|
Hi Michael,
Michael Sync wrote: What is your interest??
I don't know why I tried this language. I suppose I felt it was time to learn it. I disliked Java in college years ago - and this language reeks of Java. So I've put it off for about 7 years now.
Michael Sync wrote: Every body can't be a software engineer, programmer or developer...
I'm acutally a Security Engineer. I program to supplement my primary skills. I usually program in C++. See Artciles[^]. Most are non trivial.
I somewhat agree with you abiout Richter's book. For example, there's no need for me to exercise the Garbage Collector the way he describes. Otherwise, it's an excellent references (I believe I have all of his books).
As for the ranting of the language, it disgusts me when behavior is not documented and bugs exists. The work around for this bug (I just found it) is to prepend the namespace to the EncodingException. Where the hell is that documented. Why did I not get a compile Error or Warning? I have plenty of other examples.
For example, the TreeView SelectedNode property does not snap the view to the selection properly (TreeView and SelectedNode[^]). Another example is fixing a Splitter Panel's size. Splitter controls do not honor the desire to keep 1 panel fixed size (Splitter Panel Resize[^]). I never did find a work around for the Splitter issue.
Finally, I was never able to add a single resource to a TreeView to populate it's images. I had to break out each 16x16 bit graphic, and it them one at a time. See TreeView Images (Image Array)[^]. Coming from C++, this seems absurd to me. I add a 906x16 graphic, set size to 16. I expect the control to decuce there are 960/16 or 60 images.
Jeff
|
|
|
|
|
Jeffrey Walton wrote: I don't know why I tried this language.
I understand. It happened all the time..
Jeffrey Walton wrote: I'm acutally a Security Engineer. I program to supplement my primary skills. I usually program in C++. See Artciles[^]
I have checked your articles list.. very interesting.. As you are already familiar with programming concepts, you should not have any problem with C# too..
Jeffrey Walton wrote: As for the ranting of the language, it disgusts me when behavior is not documented and bugs exists.
I agreed that the most of MS documentation are not very good..
http://www.codeproject.com/script/comments/forums.asp?msg=2328163
http://www.codeproject.com/script/comments/forums.asp?msg=2328419
http://www.codeproject.com/script/comments/forums.asp?msg=2323999
Those links are not working.. You should copy the permalink from the threads..
Jeffrey Walton wrote: he work around for this bug (I just found it) is to prepend the namespace to the EncodingException.
So, you have solved your problem. Can you share us more about this bug that you just found?
Thanks and Regards,
Michael Sync ( Blog: http://michaelsync.net)
"Please vote to let me (and others) know if this answer helped you or not. A 5 vote tells people that your question has been answered successfully and that I've pitched it at just the right level. Thanks."
|
|
|
|
|
Hi Michael,
Michael Sync wrote: You should copy the permalink from the threads..
Forgive my ignorance on this one (I grabbed from 'http' to the message ID in the URL bar). How does one use the permalink copy?
Jeff
|
|
|
|
|
There is some links "Reply | EMail | View Thread | Permalink | Go to Thread Start" included in each thread. If you are using Firefox, you can right-click on Permalink and select "Copy Link Location".
Thanks and Regards,
Michael Sync ( Blog: http://michaelsync.net)
"Please vote to let me (and others) know if this answer helped you or not. A 5 vote tells people that your question has been answered successfully and that I've pitched it at just the right level. Thanks."
|
|
|
|
|
Hi Michael,
Sorry about the delay. Yesterday was all coding and debugging (since I did not have to waste time with UI workarounds). The effect recharged my desire to continue with C#.
Michael Sync wrote: Can you share us more about this bug that you just found?
The basic problem was an exception of user defined type EncodingException was not caught as expected in one source file. In the other source files, I had to explicitly use [Namespace].[Class]. However, in this source file (which is different than the EncodingException source file), the compiler did not Error or Warn when using just [ClassName](EncodingException). But the exception went uncaught.
When I changed From throw EncodingException to ASN1.EncodingException, the exception was caught. This leads me to believe I may have collided with another EncodingException (supplied by Microsoft?). But I was not able to locate the culprit.
Jeff
|
|
|
|
|
Jeffrey Walton wrote: As for the ranting of the language, it disgusts me when behavior is not documented and bugs exists. The work around for this bug (I just found it) is to prepend the namespace to the EncodingException. Where the hell is that documented.
I don't see where type confusion could originate, but then you only showed small parts
of your code.
Anyway I always advice people to use Exception.ToString() and not Exception.Message
to visualize exceptions; doing so you get the entire type, the message, additional
information, inner exceptions if any, and the stack traceback. Hence much more than
the single line of text in Message.
So every catch(Exception ex) {} should contain Console.WriteLine(ex.ToString())
or something equivalent.
BTW: most of your complaints seem to be about .NET, not the C# language.
The classes would behave the same in VB.NET or managed C++. If you're new to .NET
I would suggest you work trhough an introductory book (say one of Microsoft's C# books).
Hope this helps.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
If you are not familiar with C# language, don't read "CLR via C#.". This book won't be right for you.. This book is for those who already familiar with C#. You should probably read "Beginning with C#" or something like that until you get used to it..
Thanks and Regards,
Michael Sync ( Blog: http://michaelsync.net)
"Please vote to let me (and others) know if this answer helped you or not. A 5 vote tells people that your question has been answered successfully and that I've pitched it at just the right level. Thanks."
|
|
|
|
|
hi.. i got a problem creating a treeview which enables user to upload a photo/movie/sound clip through the uploading function and the data will be displayed in the treeview....
what i found on the tutorial is just regarding the treeview arrangement with child nodes...
i can do a function to upload a picture.. but how about movie? and songs clips..
|
|
|
|
|
alainlyehongloon wrote: the tutorial
What tutorial?
|
|
|
|
|
oh.. sorry.haha. i want to upload a file and the file will be displayed in the treeview categorized by year... how do i do that
|
|
|
|
|
Hi Friends,
I have an array whose members are below
int[] sayilar=new int[10]
sayilar[0]=2;
sayilar[1]=3;
sayilar[2]=5;
sayilar[3]=3;
sayilar[4]=2;
sayilar[5]=2;
sayilar[6]=5;
sayilar[7]=3;
sayilar[8]=7;
sayilar[9]=8;
I want to send these the members of sayilar array to sayilar2 array but one member can be sent to sayilar2 array only one time. For example, 5 is repeated two times in sayilar array but sending to sayilar2 array it must be only one time.
|
|
|
|
|
omegazafer wrote: I want to send these the members of sayilar array to sayilar2 array but one member can be sent to sayilar2 array only one time. For example, 5 is repeated two times in sayilar array but sending to sayilar2 array it must be only one time.
That doesn't hold much meaning now does it?
Did you mean that you wanted to copy only a single instance of the elements in sayilar to sayilar two?
Please rephrase.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
"There is no wealth like knowledge, no poverty like ignorance." Ali ibn Abi Talib
"Animadvertistine, ubicumque stes, fumum recta in faciem ferri?"
|
|
|
|
|
Yes, you understood truely, I meant that.
|
|
|
|
|
Are you required to use arrays? Could you use another alternative dynamic data structure like a List<t> ?
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
"There is no wealth like knowledge, no poverty like ignorance." Ali ibn Abi Talib
"Animadvertistine, ubicumque stes, fumum recta in faciem ferri?"
|
|
|
|
|
Firs of all, I prefer array but if you have only solution on list. You can explain.
|
|
|
|
|
The problem with arrays is that they are static in length. Once declared they can't be grown or shrunk unless you re-declare them. So in the first problem (2 arrays) assuming you copy an element from the first array to the second array and then after you have made a copy you check to see if there are any repetitions you will encounter gaps as such:
aray1: |0|1|2|3|2|5| array2: |0|1|2|3| |5|
so unless you waste extra loops to filter out the gaps into a 3rd array, you can't do much.
With a dynamic data structure such as a list, the following answers your problem:
<br />
array2 = new List<int>(array1);<br />
<br />
int repitionCounter = 0;<br />
for (int i = 0; i < array1.Length; i++)<br />
{<br />
for (int j = 0; j < array2.Count; j++ )<br />
{<br />
<br />
<br />
if (array2[j] == array1[i])<br />
{<br />
repitionCounter++;<br />
}<br />
<br />
if (repitionCounter > 1)<br />
{<br />
array2.Remove(array2[j]);<br />
--repitionCounter;<br />
}<br />
}<br />
<br />
repitionCounter = 0;<br />
}<br />
or even better, since you should be taking advantage of the Class methods:
<br />
array2 = new List<int>();<br />
<br />
for (int i = 0; i < array1.Length; i++)<br />
{<br />
if (!array2.Contains(array1[i]))
array2.Add(array1);
}<br />
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
"There is no wealth like knowledge, no poverty like ignorance." Ali ibn Abi Talib
"Animadvertistine, ubicumque stes, fumum recta in faciem ferri?"
|
|
|
|
|
int[] sayilarTwo = new int[10];
int count = 0;
for(int i=0; i<10; i++) {
bool match = false;
for(int j=0; j<i; j++) {
if(sayilar[j] == sayilar[i])
match = true;
}
if(!match) {
sayilarTwo[count] = sayilar[i];
count++;
}
}
I just bodged that togeather, it will probably work.
There's also probably better ways to do it.
My current favourite word is: PIE!
Good ol' pie, it's been a while.
|
|
|
|
|
thanks a lot, for you responses.
|
|
|
|
|
You might want to try and post this in the ASP.NET forum.
PLEASE reference this at all times when in the forums.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
"There is no wealth like knowledge, no poverty like ignorance." Ali ibn Abi Talib
"Animadvertistine, ubicumque stes, fumum recta in faciem ferri?"
|
|
|
|
|
Hi,
I'm writing a simple application which requires the user to log on. It displays a logon form and if the user passes the security check, the main form is then displayed.
On my logon form I have this:
static void Main()
{
Application.Run(new Login());
}
If the user passes security, I want the logon form to close leaving the main form open but can I do this? I can hide the form but if I close the main form, the application is still running.
Can anyone help?
Thanks
|
|
|
|
|
The trick is to show the dialog before the Application.Run. Trust me - it works. What you end up with is something like this:
static void Main()
{
using (Login login = new Login())
{
login.ShowDialog();
if (login.IsAuthenticated)
{
Application.Run(new MainForm());
}
}
} Of course, there are a couple of assumptions here. One is that your login form has an IsAuthenticated property, and the other is that your main form is called - well MainForm. Anyway, this should give you the general idea.
|
|
|
|