0

Hey I am wondering how does Java exceptions model differ that in C++ and Python?

I thought it was that only Java had checked exceptions, but from what I read Python also has checked exceptions?

Any thoughts would be great, Thanks

user1974753
  • 1,359
  • 1
  • 18
  • 32
  • Yes Python supports exceptions handling. – Grijesh Chauhan Feb 27 '13 at 18:39
  • I think Python's checked exceptions makes use of decorators to emulate Java's `throws` declaration. I don't think it's a built-in feature. – Waleed Khan Feb 27 '13 at 18:41
  • See: http://www.mindview.net/Etc/Discussions/CheckedExceptions **and** http://stackoverflow.com/questions/838460/java-exception-vs-c-exceptions – Maroun Feb 27 '13 at 18:43
  • 2
    @GrijeshChauhan Exception handling != checked exceptions. –  Feb 27 '13 at 18:44
  • @WaleedKhan What "Python's checked exceptions"? I've never seen such a thing, is it in some obscure third-party library? Then that's not really comparable IMHO. –  Feb 27 '13 at 18:45
  • @delnan Yes technically two words are `!=` :) – Grijesh Chauhan Feb 27 '13 at 18:46
  • @GrijeshChauhan What I'm saying is: Having exception handling in the language doesn't even begin to imply having checked exceptions (look up what it is; you seem to not know), so you can't say "Yes, there's exception handling" in response to a question about *checked exceptions*. –  Feb 27 '13 at 18:52
  • @delnan You have good understanding. I am just kind of user :) thanks good point. – Grijesh Chauhan Feb 27 '13 at 19:02

1 Answers1

3

Python does not have checked exceptions. But it does have exception handling mechanics.. e.g.

def test():
    raise Exception()

try:
    test()
except Exception:
    print "bugger."

# but its totally legal to just call it, and let any uncaught exceptions propagate
test()

is entirely legal thanks to the design of the python virtual machine,

public static void TestMethod(){
    throw new Exception();
}

on the other hand running code that could throw an exception (that the compiler will detect) that is not explicitly checked in Java is totally illegal. It just can't be done thanks to the design of the JVM and the byte compiler.

Jakob Bowyer
  • 33,878
  • 8
  • 76
  • 91