proposal: Go 2: Error handling with try-with-resources #29120
Labels
error-handling
Language & library change proposals that are about error handling.
FrozenDueToAge
Proposal
Milestone
Currently:
Proposal inspired by Java 7's try-with-resources:
Error messages are the same format, simplified version:
Notes:
Open()
,Create()
, andCopy()
functions signature must befunction() T, error
where T is a generic type which implements aClose()
function.check
executes instructions one by one and implicitely does theerr != nil
operation, if err isn'tnil
, the relatedcatch
block is executed. Syntactic sugar: If the relatedcatch
block does not exists, try to execute the lastcatch
block.if err := w.Close(); err != nil { ... }
block, but should a close method return an error? Even Java's or C#'s close function doesn't return anything :)The text was updated successfully, but these errors were encountered: