0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Rust vs Python:例外処理

Last updated at Posted at 2023-05-26

例外処理 in Python

def raise_exception():
    raise Exception("例外が発生しました")

def main():
    try:
        raise_exception()
    except Exception as e:
        print("Exception: {}".format(e))


if __name__ == "__main__":
    main()

例外処理 in Rust

fn raise_exception() -> Result<(), String> {
    Err("例外が発生しました".to_string())
}


fn main() {
    match raise_exception() {
        Ok(_) => println!("OK"),
        Err(e) => println!("Error: {}", e),
    }
}
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?