Abort on exception?

  • Thread starter Thread starter sweetiecakes
  • Start date Start date
S

sweetiecakes

A simple Google search didn't result anything (although I'm not known
for my Google usage skills), but how would I stop the operation when an
exception occurs?

(For example, how would I prevent "int four = 2 + 2;" from being
executed in the following example:

try {
int division = 100/0;
int four = 2 + 2;
}
catch (DivideByZeroException de) {
Console.WriteLine("you've destroyed the world, way to go");
} ?)
 
A simple Google search didn't result anything (although I'm not known
for my Google usage skills), but how would I stop the operation when an
exception occurs?

(For example, how would I prevent "int four = 2 + 2;" from being
executed in the following example:

try {
int division = 100/0;
int four = 2 + 2;}

catch (DivideByZeroException de) {
Console.WriteLine("you've destroyed the world, way to go");

} ?)

Using try-catch, when an exception is thrown resulting as in your
catch block message, operation is stopped in "try" and catch block is
executed.

HTH,

Onur Güzel
 
(For example, how would I prevent "int four = 2 + 2;" from being executed
in the following example:

It wont be executed. Put a breakline on your code and step through it to
see what happens.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top