answersLogoWhite

0

Exceptions are the error handling mechanism of C#. When an error occurs, an exception is thrown using this syntax:

void BadMethod()

{

bool Error = true;

if (Error)

{

throw new Exception("Whoops!");

}

}

Methods can then handle exceptions using a try/catch/finally syntax. The code that you are trying to execute goes between a try { } block, the code to handle the error goes between the catch { } block. Any code that you put between the finally { } block will always execute after the exception handling code is complete (or if an error did not occur).

void test()

{

try

{

BadMethod();

catch (Exception ex)

{

Console.WriteLine("An error occured. The description is: " + ex.Description);

}

finally

{

Console.WriteLine("I'm done!");

}

}

User Avatar

Wiki User

15y ago

What else can I help you with?

Related Questions

Stack overflow Exception source code in c sharp?

You have to ask Microsoft for the source code


What is the use of debug folder in solution explorer in c sharp?

The debug folder in solution explorer in C sharp is to trace routes to directories.


What are the notes to?

A sharp G G E sharp G E sharp A sharp A sharp C C A sharp C E sharp G A G E sharp A sharp A sharp A sharp G E sharp C this is not on the Flute btw idk what instrument its on


Can you use random method in If Statement in c sharp?

Yes


What is exeption in c sharp?

an exception is an error.it is usual to use exception handlers in your program to guard against crashesfor exampletry{DatabaseConnection.Open();}catch(Exception ex){MessageBox.Show(ex.Message);}finally{DatabaseConnection.Close();}This attempts to open a connection and if there is an error it shows a message box with the pre defined message for that exception. then it cleans up by closing the connection if any part was opened. this stops the program from crashing all the time.


What are the notes to fireflies?

A sharp G G E sharp G E sharp A sharp A sharp C C A sharp C E sharp G A G E sharp A sharp A sharp A sharp G E sharp C this is not on the flute btw idk what instrument its on


How do you play Simpson theme on keyboard?

here it is C,E,F SHARP,A,G,E,C,A,F SHARP,F SHARP,F SHARP,G,A SHARP,C,C,C,C


What key signature has G sharp B sharp and C sharp?

C# Major


Which computer language more use in IT field?

C Sharp (C#) .Net Because its so powerful


What is difference between exception handling in C and Java?

Easy: there is no exception-handling in C.


What are the notes for the c sharp harmonic scale?

C sharp, D sharp, E natural, F sharp, G sharp, A natural, B sharp & C sharp We call the note C "B sharp" to avoid using the same letter name twice. If we used the note name "C" we would have 2 C-notes and no B-notes in the scale!


What are the basic difference between c sharp and vbnet?

They use different syntax.