473,394 Members | 1,752 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,394 software developers and data experts.

Try - catch

Hi,

Is there a way to check if there are no exceptions?
I now use the understanding code, are there other options?

bool noExceptions = true;
try { }
catch { noExceptions = false; }

if (noExceptions == true) { }

Thanks!
Nov 17 '05 #1
2 1165
Arjen,

That's pretty much the way you would do it. Normally though, I wouldn't
recommend swallowing the exception like that unless you had to.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Arjen" <bo*****@hotmail.com> wrote in message
news:dd**********@news5.zwoll1.ov.home.nl...
Hi,

Is there a way to check if there are no exceptions?
I now use the understanding code, are there other options?

bool noExceptions = true;
try { }
catch { noExceptions = false; }

if (noExceptions == true) { }

Thanks!

Nov 17 '05 #2
Arjen,

Your code:

bool noExceptions = true;
try {
// CODE BLOCK 1
}
catch { noExceptions = false; }

if (noExceptions == true) {
// CODE BLOCK 2
}

Could be rewritten as follows:

try {
// CODE BLOCK 1
// CODE BLOCK 2 - happens only if no exceptions in block 1 !!
}
catch {
}

(no variable needed). But then as Nicholas said, instead of "swallowing" the
exception, generally is better to simply write:

// CODE BLOCK 1
// CODE BLOCK 2

(no try-catch at all) and let the calling context to handle the possible
exception.

Regards - Octavio

"Arjen" <bo*****@hotmail.com> escribió en el mensaje
news:dd**********@news5.zwoll1.ov.home.nl...
Hi,

Is there a way to check if there are no exceptions?
I now use the understanding code, are there other options?

bool noExceptions = true;
try { }
catch { noExceptions = false; }

if (noExceptions == true) { }

Thanks!

Nov 17 '05 #3

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

Similar topics

11
by: kaeli | last post by:
Hey all, I'd like to start using the try/catch construct in some scripts. Older browsers don't support this. What's the best way to test for support for this construct so it doesn't kill...
11
by: Pohihihi | last post by:
I was wondering what is the ill effect of using try catch in the code, both nested and simple big one. e.g. try { \\ whole app code goes here } catch (Exception ee) {}
23
by: VB Programmer | last post by:
Variable scope doesn't make sense to me when it comes to Try Catch Finally. Example: In order to close/dispose a db connection you have to dim the connection outside of the Try Catch Finally...
32
by: cj | last post by:
Another wish of mine. I wish there was a way in the Try Catch structure to say if there wasn't an error to do something. Like an else statement. Try Catch Else Finally. Also because I...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.