feat: added cleanscript
This commit is contained in:
30
ch09/ch09-00-error-handling.html
Normal file
30
ch09/ch09-00-error-handling.html
Normal file
@@ -0,0 +1,30 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Error Handling</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1 id="error-handling"><a class="header" href="#error-handling">Error Handling</a></h1>
|
||||
<p>Errors are a fact of life in software, so Rust has a number of features for
|
||||
handling situations in which something goes wrong. In many cases, Rust requires
|
||||
you to acknowledge the possibility of an error and take some action before your
|
||||
code will compile. This requirement makes your program more robust by ensuring
|
||||
that you’ll discover errors and handle them appropriately before deploying your
|
||||
code to production!</p>
|
||||
<p>Rust groups errors into two major categories: recoverable and unrecoverable
|
||||
errors. For a <em>recoverable error</em>, such as a <em>file not found</em> error, we most
|
||||
likely just want to report the problem to the user and retry the operation.
|
||||
<em>Unrecoverable errors</em> are always symptoms of bugs, such as trying to access a
|
||||
location beyond the end of an array, and so we want to immediately stop the
|
||||
program.</p>
|
||||
<p>Most languages don’t distinguish between these two kinds of errors and handle
|
||||
both in the same way, using mechanisms such as exceptions. Rust doesn’t have
|
||||
exceptions. Instead, it has the type <code>Result<T, E></code> for recoverable errors and
|
||||
the <code>panic!</code> macro that stops execution when the program encounters an
|
||||
unrecoverable error. This chapter covers calling <code>panic!</code> first and then talks
|
||||
about returning <code>Result<T, E></code> values. Additionally, we’ll explore
|
||||
considerations when deciding whether to try to recover from an error or to stop
|
||||
execution.</p>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user