Skip to content
This repository was archived by the owner on Aug 16, 2021. It is now read-only.

Commit 52977e1

Browse files
committed
try! -> ?
Fixes #172
1 parent 74fe8cf commit 52977e1

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

src/lib.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
//! and implementation boilerplate necessary for fulfilling a
5656
//! particular error-handling strategy. Most importantly it defines a
5757
//! custom error type (called `Error` by convention) and the `From`
58-
//! conversions that let the `try!` macro and `?` operator work.
58+
//! conversions that let the `?` operator work.
5959
//!
6060
//! This library differs in a few ways from previous error libs:
6161
//!
@@ -211,21 +211,20 @@
211211
//! strings and `ErrorKind` have `From` conversions to turn them into
212212
//! `Error`.
213213
//!
214-
//! When the error is emitted inside a `try!` macro or behind the
215-
//! `?` operator, the explicit conversion isn't needed; `try!` will
216-
//! automatically convert `Err(ErrorKind)` to `Err(Error)`. So the
217-
//! below is equivalent to the previous:
214+
//! When the error is emitted behind the `?` operator, the explicit conversion
215+
//! isn't needed; `Err(ErrorKind)` will automatically be converted to `Err(Error)`.
216+
//! So the below is equivalent to the previous:
218217
//!
219218
//! ```
220219
//! # #[macro_use] extern crate error_chain;
221220
//! # fn main() {}
222221
//! # error_chain! { errors { FooError } }
223222
//! fn foo() -> Result<()> {
224-
//! Ok(try!(Err(ErrorKind::FooError)))
223+
//! Ok(Err(ErrorKind::FooError)?)
225224
//! }
226225
//!
227226
//! fn bar() -> Result<()> {
228-
//! Ok(try!(Err("bogus!")))
227+
//! Ok(Err("bogus!")?)
229228
//! }
230229
//! ```
231230
//!
@@ -437,7 +436,7 @@
437436
//! can still be included in the error chain. They are considered "foreign
438437
//! errors", and are declared using the `foreign_links` block of the
439438
//! `error_chain!` macro. `Error`s are automatically created from
440-
//! foreign errors by the `try!` macro.
439+
//! foreign errors by the `?` operator.
441440
//!
442441
//! Foreign links and regular links have one crucial difference:
443442
//! `From` conversions for regular links *do not introduce a new error
@@ -580,14 +579,14 @@ impl<'a, T> fmt::Display for Display<'a, T>
580579
where T: ChainedError
581580
{
582581
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
583-
try!(writeln!(fmt, "Error: {}", self.0));
582+
writeln!(fmt, "Error: {}", self.0)?;
584583

585584
for e in self.0.iter().skip(1) {
586-
try!(writeln!(fmt, "Caused by: {}", e));
585+
writeln!(fmt, "Caused by: {}", e)?;
587586
}
588587

589588
if let Some(backtrace) = self.0.backtrace() {
590-
try!(writeln!(fmt, "{:?}", backtrace));
589+
writeln!(fmt, "{:?}", backtrace)?;
591590
}
592591

593592
Ok(())

src/quick_main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// Convenient wrapper to be able to use `try!` and such in the main. You can
1+
/// Convenient wrapper to be able to use `?` and such in the main. You can
22
/// use it with a separated function:
33
///
44
/// ```

tests/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ mod foreign_link_test {
367367
}
368368

369369
fn try_foreign_error() -> Result<()> {
370-
try!(Err(ForeignError { cause: ForeignErrorCause {} }));
370+
Err(ForeignError { cause: ForeignErrorCause {} })?;
371371
Ok(())
372372
}
373373
}

0 commit comments

Comments
 (0)