Linked by fran on Fri 22nd Jul 2011 21:02 UTC
Thread beginning with comment 482176
To view parent comment, click here.
To read all comments associated with this story, please click here.
To view parent comment, click here.
To read all comments associated with this story, please click here.
RE[2]: As a programmer...
by henderson101 on Mon 25th Jul 2011 13:50
in reply to "RE: As a programmer..."
This was probably your problem. Panic/Recover aren't used for error handling. They are used for handling exceptional situations that the programmer wasn't expecting and thus the program can't handle(usually programmer error). It's intentionally annoying to use to discourage people over using it.
Well, no.. surely the concept is similar as the following (Sorry, OS news seems to flatten the indentation in the preview, so probably the post too):
class X
{
void static Main()
{
X x = new X();
try
{
x.Whatever();
}
finally
{
//clean up or whatever
x.Dispose(); //e.g.
x = null; //...or
}
catch(Exception ex)
{
//silently swallow anything we don't otherwise handle
}
}
void Whatever()
{
try
{
y();
}
finally
{
//defer
}
catch(MySuperException ex)
{
//recover
}
}
void y()
{
try
{
throw new SomeUnhandledException("We don't handle this");
}
catch(SomeOtherException ex)
{
//recover
}
catch(AnotherKindOfException ex2)
{
//recover
}
}
}
Idiomatic error handling in Go is done using the multiple return statements and checking for returned error values.
Exception handling and Error handling go hand in hand in modern OO languages.
RE[3]: As a programmer...
by jessta on Mon 25th Jul 2011 16:33
in reply to "RE[2]: As a programmer..."
Well, no.. surely the concept is similar as the following (Sorry, OS news seems to flatten the indentation in the preview, so probably the post too):
It's possible to use panic/recover as a fairly limited traditional exception handling system, but it's not nice to use and Go programmers won't expect it. Similarly you can return null to indicate errors in Java but Java programmers won't expect that either.
Exception handling and Error handling go hand in hand in modern OO languages.
They are distinct concepts and Go treats them as such.
By making them distinct you make your error handling easier to reason about and more resilient to changes in other parts of the code base. Even Java's checked exceptions have a neat trick of hiding the source of an exception from the code that has to handle it.





Member since:
2005-08-17
This was probably your problem. Panic/Recover aren't used for error handling. They are used for handling exceptional situations that the programmer wasn't expecting and thus the program can't handle(usually programmer error). It's intentionally annoying to use to discourage people over using it.
Idiomatic error handling in Go is done using the multiple return statements and checking for returned error values. There are a few tutorials on the website and the language spec is easy to read. The standard library documentation is pretty good(far better than the vagueness of php's docs), but some examples might help new devs.