|
Sorry I think I didn't make myself clear: what I mean is it's perfectly normal that the application, when run directly (i.e. running the exe file) crashes. But this will happen for both Debug and Release!
If you run the app inside the VS debugger, on the contrary, then it will behave differently: both Debug and Release versions will catch the exception and show the dialog box.
This happens because exception handling is slightly different while running the debugger.
Just to be sure I made the experiment myself just now, and I confirm what I said.
In order to capture the exception you must use a local try/catch block in the ModelDialog form.
There is no way I know of handling the exception the way you want to. I suggest your change your approach. Consider this (just a raw example):
namespace ModelDialogExceptions
{
public partial class ModelDialog : Form
{
public ModelDialog()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
throw new System.IO.FileNotFoundException("");
DialogResult = DialogResult.OK;
}
catch (Exception)
{
DialogResult = DialogResult.Abort;
}
}
internal static bool GetMyFile()
{
ModelDialog md = new ModelDialog();
switch (md.ShowDialog())
{
case DialogResult.OK:
return true;
case DialogResult.Abort:
throw new ApplicationException("Operation aborted, an exception may have been thrown.");
case DialogResult.Cancel:
throw new ApplicationException("Cancelled by user.");
default:
throw new ApplicationException("Unknown error.");
}
}
}
}
namespace ModelDialogExceptions
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
if (ModelDialog.GetMyFile())
{
MessageBox.Show("All ok!");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
2+2=5 for very large amounts of 2
(always loved that one hehe!)
|
|
|
|
|
thanks for such wonderful reply!!
You know what I did the same (Because didnt had any other alternative)
I thought I could share you with you all guys this unusual behavior, might be somebody knowing the exactly why this happens?
anyways thanks for reply!
|
|
|
|
|
As I said, it happens because of the debugger. The debugger contains an exception handler which "watches" for exceptions while running the code. When an exception is caught, it will walk up not only the function call stack (which is what the runtime does when you run the exe), but the program flow - searching for a try/catch block which can catch the exception. If it's not found, then the debugger's handler kicks in (it's the piece of code that shows you the exception message box and lets you point at the code which raised it).
Now, calling ShowDialog() is not like calling any other function. A normal function call will just transfer the current thread's execution to the function's code, saving the return address on the stack, and return to the calling code when the function exits. This allows for the raised exception to be passed directly up to the calling code and get caught by the upper level try/catch block.
What happens when you call ShowDialog() is that the new form is created and shown, and the UI's message pump (remember it all runs on a single thread, but it's message-based) starts managing it together with all other open forms, with the only exception that other forms will be "frozen". When the dialog closes and returns its result, this is passed back to the calling code, and execution flow returns there, but in this case exceptions do not cross the boundaries of forms, since there's no "bridging" code for that to happen.
This is the best explanation I can give, I hope it clears your doubts. Maybe some other guy can give a more complete or deeper explanation.
2+2=5 for very large amounts of 2
(always loved that one hehe!)
|
|
|
|
|
Yeh Moreno Airoldi !!!!
that was great info !!!
thanks a ton for such nice explanation!!
|
|
|
|
|
My pleasure.
2+2=5 for very large amounts of 2
(always loved that one hehe!)
|
|
|
|
|
Hi falks!
I need to parse a text file including an NC code which is a simple CNC tool motion determinator. In the file, each line shows the instantaneous positon of the tool tip. For example, the first line is X0 Y0 Z0 F200 and second line X10 Y10 Z10 this means that the tool is at (0,0,0) and will go to (10,10,10) with a speed of 200 m/min. This motion will take some time. Depending on the machine tool specificaion (user will enter), according to sampling time entered by user (0.1 second for example) succesive points will be determined between (0,0,0) and (10,10,10) one point in each 0.1 second. I have to parse the text file and give a list as an output showing the position of the tool at eah multiples of the sampling time. A sample NC code is:
G1X0Y0Z0F200
X10.Y10.Z10.
X21.Y16.Z8.
Y10.Z5.
G1 means linear motion. I will use only linear motion. Blanks between the characters are not important. However, to specify X position of tool as 10 it should be written as "X10." or "X10.0". X10 means 10*sampling time (e.g 10*0,1=1). Any caharacter which is not writen in a line means that it is the same as the last written form in earlier lineas. My output will be like
X Y Z
0
0,1 1 1 1
0,2 2 2 2
0,3 . . .
. . . .
.
.
I need help!
|
|
|
|
|
What is the issue ? String parsing ? You can use regex for this, or just use methods on the string class.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
|
How is 'hi' a valid subject line ?
Use a delegate to communicate between forms
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
A couple of things:
1) Read the bit at the top of the page entitled: "How to get an answer".
2) Describe your problem in the subject. "Hi" and "Hello guys" do not describe your problem.
3) Explain your problem as clearly as you can.
4) Tell us what you have tried.
and very definately:
5) DO NOT WAIT THREE MINUTES AND THEN POST THE SAME PROBLEM AGAIN IN WORSE ENGLISH
As all you will do is annoy people.
Thank you for your attention.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Same with "Hello Guys"..huh..??
|
|
|
|
|
You are right.
I think he don't know how to ask a question
|
|
|
|
|
|
engg_sukreet wrote: .Anyone know answer reply as soon as possible......
This is rude, and you appear to be dumb. Why did you post this twice, just to make the subject even more useless, and the message shorter ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
"Hello Guys"----> "???????"
"Anyone know answer reply as soon as possible......"------> means no reply !!
|
|
|
|
|
stancrm wrote: "Anyone know answer reply as soon as possible......"------> means no reply !!
It's a pity Chris instituted new rules "How to answer a question" or I'm sure he'd have got some replies...
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Very frustrating these new rules - and almost noone post programming questions in the Lounge any more.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Wat kind of a idiot are you?
PS: You have a sad sense of humor
Aman
|
|
|
|
|
Amangang wrote: Wat kind of a idiot are you?
PS: You have a sad sense of humor
Aman
The kind that can spell. Why, "Wat" kind do you think I should be?
Did I respond rudely, stupidly, or just not to your personal preferance? Do tell - as an idiot I have nothing better to do than wait for your response.
Breathlessly anticipating your further communications...
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Just trying not to type so much, didnt realise that i had to speak to you without abbreviations. By the way what you said was rude and probably insulted someone.
Aman
|
|
|
|
|
Amangang wrote: By the way what you said was rude and probably insulted someone.
Would you care to elucidate? Which part was rude, and which part insulted somebody?
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
hey budy .... if any one answers you something ... please tell me .... because I am going tell u that you r not the only dumb here..... lool
|
|
|
|
|
so i get text like this grabbed from a webpage:
accountid=176153type=premservertime=1249458970addtime=1163095909validuntil=1251617287username=myUsernamedirectstart=1protectfiles=0rsantihack=1plustrafficmode=0mirror=mirror2=mirror3=mirror4=jsconfig=1email=myemail@hotmail.comlots=0points=13382curfiles=3420curspace=267218323804bodkb=26430697premkbleft=4598808refpoints=13refrate=200
and i want to split this to display only some of the information, and in a neat form.
for example:
Accountid = 176153
Username = myUsername
Valid Until = 1251617287
RS AntiHack = Yes
Email = myemail@hotmail.com
i want this to be displayed in a textbox
and if its not to diffucult, can someone point me to the right direction where i can display each detail in a listview?
ive got all the columns and whatnot all done.
thanks alot
|
|
|
|
|
I think, there are "&" between each record.
It must be something like this : "accountid=176153&type=prem..."
Then you can split it using "&".
string input = "accountid=176153&type=prem...";
string[] s = input.Split('&');
Then split each record using "=".
|
|
|
|
|
hmm ok.
but im not too sure that there is :S
i think it has a new line between each part, but it doesnt show when it displays in a text box, only in a message box.
the official way that the results come out it is:
accountid=$accountid (integer)
type=$type (prem or col)
servertime=$time (integer)
addtime=$addtime (integer)
validuntil=$validuntil (integer)
username=$username (string)
directstart=$directstart (integer)
protectfiles=$protectfiles (integer)
rsantihack=$rsantihack (integer)
plustrafficmode=$plustrafficmode (integer)
mirror=$mirror (string)
mirror2=$mirror2 (string)
mirror3=$mirror3 (string)
jsconfig=$jsconfig (string)
email=$email (string)
lots=$lots (integer)
points=$points (integer)
curfiles=$curfiles (integer)
curspace=$curspace (integer)
bodkb=$bodkb (integer)
prempoints=$prempoints (integer)
premkbleft=$premkbleft (integer)
refpoints=$refpoints (integer)
refrate=$refrate (integer in cents)
|
|
|
|