filmov
tv
Learn Java Programming - Exception Handling: Try and Catch Tutorial

Показать описание
There are tons and tons of methods in Java that are predisposed to causing exceptions and believe it or not, that is a good thing. It is too early in the topic of exception handling to explain at this point, but once you understand all of the concepts, you will see why. The very heart and soul of exception handling relies on two Java keywords: try and catch. If you've ever watched that show Mythbusters, then you know that Adam and Jamie just love to blow stuff up. They poke and prod and try everything under the sun to break stuff and sometimes they just blow it up in the end. If they were programmers I imagine it would go something like this ... "Hey Adam, let's try this line of code and if it goes kaboom, then we'll catch the pieces and see if we can salvage anything". Programming is just like real life; think of a method as something of a chainsaw ... a chainsaw is designed to cut down trees, but there is nothing stopping you from trying to cut the door off of your car and if you try that there will be exceptions like a trip to the ER, a broken chain, etc. Methods are designed to perform a specific task and depending on their level of complexity it is impossible to anticipate how someone may choose to utilize the method, so if you are the one writing the method you will try to anticipate specific abuses and throw exceptions for those situations.