Being new to programming I have only just found out that you can specifically catch certain types of errors and tie code to only that type of error.
I’ve been researching into the subject and I don’t quite understand the syntax e.g.
catch (InvalidCastException e)
{
}
I understand the InvalidCastException is the type of error being handled, however I am unsure of what e is.
Could somebody please explain this?
The
eis the object that holds the data specific to the exception. If you look into different types of exceptions, you’ll see that they all have different type of data. Many don’t, but many do, and when they do, they can help you identify just exactly what happened instead of just getting a generic error.For example, the
NotFiniteNumberExceptiondefines an additional property calledOffendingNumberthat isn’t present in a normalExceptionobject… This then provides additional data that you might need to figure out exactly what happened.