4 ms·
If code can panic it should be documented. Code you write shouldn't ever panic without good reason during the regular runtime of your application. A panic means
by Philip-J-Fry 5y ago
If code can panic it should be documented. Code you write shouldn't ever panic without good reason during the regular runtime of your application. A panic means that the current goroutine has encountered an unrecoverable error, which is usually only the case for bugs such as out of range indexes or nil pointers.
- dcow 5y agoWhich would be exceptions you can handle in C#.
- mikeklaas 5y agoYou can catch and recover from panic()'s in go, too.
- Philip-J-Fry 5y agoThe point being that an exception in C# can be any error. You can throw an exception if the weather is wrong. A panic is fundamentally something that should never happen. You should catch panics at the root of your application for the sake of keeping the application running. But at no point should you ever expect a panic to be thrown like you would an exception. Errors are for that case.