11 ms·
> try catch is different keywords from virtually all other languages Python : try/except/finally/else C# : try/catch/finally (no equivalent of “else”) VB.net
by dragonwriter 3y ago
> try catch is different keywords from virtually all other languages
Python : try/except/finally/else
C# : try/catch/finally (no equivalent of “else”)
VB.net : try/catch/finally (no equivalent of “else”)
JavaScript : try/catch/finally (no equivalent of “else”)
Java : try/catch/finally (no equivalent of “else”)
Ruby: begin/rescue/ensure (no equivalent of “else”)
C++: try/catch (no equivalent of “finally” or “else”)
Python’s try/except/finally/else seem to use nearly the same keywords as many other popular languages (Ruby is an oddball here, using similar semantics with different keywords), except that it uses “except” in place of “catch”, and “else” is a unique feature, and C++ lacks “finally”.
EDIT: The above has been edited throughout to correct an initial thinko that had Python using the common “catch” instead of “except”, which I really can’t explain because I've been wading throw Python exception handling code a lot recently.
- SirensOfTitan 3y agoPython uses try/except and instead of throw uses raise.
- robertlagrant 3y agoPython is try/except, not try/catch. I don't think it matters in the least that it's different, but it is different.
- graypegg 3y agoRuby does have a good reason to be oddball IMO. begin isn't always required. When inside a method, module, class, or do...end block definition (read: most of the time), you're able to use the rescue keyword solo. Anything raising an exception in the method above the rescue keyword will be caught. It can also be used postfixed to a statement that might raise an exception. Ruby is oddball here because it's subtly different. def a_method @value = dangerous_method_call rescue "default value in case of exception" do_something_else @value rescue puts "an error, oh no" end