---
title: "Discussion on \"Way to C++: 6. Exception Safe\" | Hashnode"
description: "Discussion on \"Way to C++: 6. Exception Safe\". 前言\n考慮以下函數:\nint Calculate(int n) {  \n    int *arr1 = new int[n];  \n    int *arr2 = new int[n];  \n    delete[] arr1;  \n    delete[] arr2;  \n    return n+1;  \n}\n\n看起來很好，在一開始 new 的陣列在離開函數時都釋放掉了。\n但是其實會有問題的:"
url: "https://hashnode.com/posts/way-to-cpp-6-exception-safe/624bb9722b09bb392ea5c02c"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Way to C++: 6. Exception Safe](https://notes.mukyu.dev/way-to-cpp-6-exception-safe?utm_source=hashnode&utm_medium=feed)

前言 考慮以下函數: int Calculate(int n) { int \*arr1 = new int\[n\]; int \*arr2 = new int\[n\]; delete\[\] arr1; delete\[\] arr2; return n+1; } 看起來很好，在一開始 new 的陣列在離開函數時都釋放掉了。 但是其實會有問題的:

May 10, 2020 · 1 min read · notes.mukyu.dev  
Updated Oct 28  
Read the article

-   [#cpp](https://hashnode.com/tag/cpp)

## Written by

[Patchouli](https://hashnode.com/@mudream4869)

@mudream4869 · Uohout

  
[View profile](https://hashnode.com/@mudream4869)

工程師帕秋莉~

後端工程師。 不定時張貼一些寫扣時的筆記，有時英文，有時中文。 「如果，我是魔女的話...」

## Responses

Markdown supported · ⌘↵ to post

No responses yet.
