Re:Mojo: It’s Finally Here
by robertlagrant on Thursday September 07, 2023 @04:28PM
(#37425089)
Python is try/except, not try/catch. I don't think it matters in the least that it's different, but it is different.
Re:Mojo: It’s Finally Here
by SirensOfTitan on Thursday September 07, 2023 @04:26PM
(#37425066)
Python uses try/except and instead of throw uses raise.
Ruby 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
Python : try/catch/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/catch/finally/else seem to use exactly the same keywords as many other popular languages (Ruby is an oddball here, using similar semantics with different keywords), except that “else” is a unique feature, and C++ lacks “finally”.