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.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.