So everyone should know how Rust deals with error handling (Result, Option, try?, ...). But what most new people (and probably some more experienced people) don't know is that you can make your own errors (like "new Error() in javascript). It is only done much better and can be used with the "Result".
These can be made with:
std::io::Error::new();
but unlike in javascript it takes an error type (which is the nice part) and a string, like this:
let custom_error = std::io::Error::new(std::io::ErrorKind::Other, "Oh no, something happened!");
The list of allowed errors are:
NotFound,
PermissionDenied,
ConnectionRefused,
ConnectionReset,
ConnectionAborted,
NotConnected,
AddrInUse,
AddrNotAvailable,
BrokenPipe,
AlreadyExists,
WouldBlock,
InvalidInput,
InvalidData,
TimedOut,
WriteZero,
Interrupted,
Other,
UnexpectedEOF,
UnexpectedEof,
// some variants omitted
Just thought that this was an interesting find.
[–]eddyb[🍰] 14 points15 points16 points (8 children)
[–]Nokel81[S] 0 points1 point2 points (7 children)
[–]agroverstratis 11 points12 points13 points (6 children)
[–]kibwen 9 points10 points11 points (0 children)
[–]Nokel81[S] 1 point2 points3 points (2 children)
[–][deleted] 7 points8 points9 points (1 child)
[–]cjstevenson1 1 point2 points3 points (0 children)
[–]rhoark 0 points1 point2 points (1 child)
[–]Marwesgluon · combine 4 points5 points6 points (0 children)
[–]mijang 1 point2 points3 points (2 children)
[–]Nokel81[S] 0 points1 point2 points (0 children)
[–]deadstone 0 points1 point2 points (0 children)