473,406 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 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 5361
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.