Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how exceptions work?

Status
Not open for further replies.

wolf73

Programmer
Feb 12, 2006
93
CA
How does exceptions work, are these just error message, or do they stop the program right there.

throw new DataInconsistancyException("No of colums in the table do not match number of colums in the array");
 
No exceptions do not stop program execution straight away.

They are useful as they allow the opposite and therefore you can deal with any exceptions (errors) that are thrown(triggered).

You use exceptions by writing try/catch blocks in your code:

Code:
try
{
    // Do something here
}
catch (exceptionType)
{
    // There was an error doing something
}

So in the catch block you can deal with any exception that is caught.

Another good thing is that you can catch different types of exceptions too. i.e.

Code:
try
{
    // Validate an integer '$I'
}
catch (isNullException)
{
    // $I was empty
}
catch (exception)
{
    // General exception case
}

So the code will run through the catch blocks till it finds one that is appropriate. If there isn't one then this will throw an 'Uncaught Exception error' which WILL stop your script.

Chris MacPherson


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top