Using try catch block for your code is always a good practice. Using try catch block you come to know about the different types of error and exceptions.
Here is the synatx:
your block of code
catch(Exception e)// here if you know the type of exception going to happen you can mention that.