472,986 Members | 2,906 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,986 software developers and data experts.

try-catch, go to catch by statement

try
{
if(i==3)
goto catch;

Console.WriteLine(i);

}
catch
{
Console.WriteLine("i = 3");
}
any statement can do the below job?
goto catch;
or i must write a dirty statement like open a non exceed file?

Thanks
Aug 26 '08 #1
5 5342
throw an exception :-)

Aug 26 '08 #2
On 26 Aug., 12:02, "macneed" <macn...@yahoo.com.hkwrote:
* * * * * * try
* * * * * * {
* * * * * * * * if(i==3)
* * * * * * * * * * goto catch;

* * * * * * * * Console.WriteLine(i);

* * * * * * }
* * * * * * catch
* * * * * * {
* * * * * * * * Console.WriteLine("i = 3");
* * * * * * }

any statement can do the below job?
goto catch;
or i must write a dirty statement like open a non exceed file?
Check out "throw"

Aug 26 '08 #3
macneed was thinking very hard :
try
{
if(i==3)
goto catch;

Console.WriteLine(i);

}
catch
{
Console.WriteLine("i = 3");
}
any statement can do the below job?
goto catch;
or i must write a dirty statement like open a non exceed file?

Thanks
you could throw an exception yourself:
throw new Exception("i == 3");

There is no need to do something illegal just to get an exception to be
thrown.
But I don't think you should use exceptions for this. Why not just a
regular if/else?

Hans Kesting
Aug 26 '08 #4
Oh man. Please don't think in "goto" terms, let alone try to type them.
.......

http://blogs.msdn.com/kcwalina/archi...16/396787.aspx
(A great post by Krzysztof Cwalina on exceptional handling)


"macneed" <ma*****@yahoo.com.hkwrote in message
news:48********@127.0.0.1...
try
{
if(i==3)
goto catch;

Console.WriteLine(i);

}
catch
{
Console.WriteLine("i = 3");
}
any statement can do the below job?
goto catch;
or i must write a dirty statement like open a non exceed file?

Thanks

Aug 26 '08 #5
On Aug 26, 2:02*pm, "macneed" <macn...@yahoo.com.hkwrote:
* * * * * * try
* * * * * * {
* * * * * * * * if(i==3)
* * * * * * * * * * goto catch;

* * * * * * * * Console.WriteLine(i);

* * * * * * }
* * * * * * catch
* * * * * * {
* * * * * * * * Console.WriteLine("i = 3");
* * * * * * }

any statement can do the below job?
bool failed = false;
try
{
if (i == 3)
{
failed = true;
}
else
{
Console.WriteLine(i);
}
}
catch
{
failed = true;
}
if (failed)
{
Console.WriteLine("i = 3");
}
Aug 26 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

39
by: Erlend Fuglum | last post by:
Hi everyone, I'm having some trouble sorting lists. I suspect this might have something to do with locale settings and/or character encoding/unicode. Consider the following example, text...
4
by: Brian Alexander | last post by:
Hello; I'm curious to know how people preserve exceptions that arise in a try ... finally block. Consider this example: try: getResource() doSomething() finally: alwaysFreeResource()
13
by: KefX | last post by:
This may have been discussed before, but I'm kind of confused as to why Python doesn't support having both an except ~and~ a finally clause, like this: try: raise RuntimeException except:...
7
by: Robert Brewer | last post by:
Alex Martelli wrote in another thread: > One sign that somebody has moved from "Python newbie" to "good Python > programmer" is exactly the moment they realize why it's wrong to code: > > ...
9
by: David Stockwell | last post by:
In referring to my copy of the python bible, it tells me I can't use all three items 'try' except and finally. I can use the t/f or t/e combinations though What combination can i use if i want...
26
by: djw | last post by:
Hi, Folks- I have a question regarding the "proper" use of try: finally:... Consider some code like this: d = Device.open() try: d.someMethodThatCanRaiseError(...) if SomeCondition: raise...
1
by: djw | last post by:
c.l.p- I am having trouble understanding how one is supposed to correctly utilize try:...except:...finally: in real code. If I have a block of code like: def foo(): try: ... some code that...
40
by: Steve Juranich | last post by:
I know that this topic has the potential for blowing up in my face, but I can't help asking. I've been using Python since 1.5.1, so I'm not what you'd call a "n00b". I dutifully evangelize on the...
3
by: Bob Rock | last post by:
Hello, this is something I've been asking myself for sometime ... and now I'd like to clarify this point. When should the try block start in a method??? What I mean is, does having all the code...
2
by: Abubakar | last post by:
Hi all, The variables declared inside try block cant be accessed inside its corresponding finally block. When I used to explain finally concept to anyone I would usually tell them (briefly) that...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.