搜尋此網誌

2026年1月27日星期二

Exception handling in C++

Exception handling in C++ is a structured way to detect and manage runtime errors using try, catch, and throw keywords, allowing programs to recover gracefully instead of crashing. It helps deal with issues like division by zero, invalid memory access, or file (input and output) I/O failures.

try block

    Contains code that might generate an exception.

    Example: risky operations like division or file handling.

throw keyword

    Used to signal that an error has occurred.

    Example: throw "File not found";

catch block

    Defines how to handle the exception.

    Example: catch (const char* msg) { cout << msg; }


#include <iostream>

using namespace std;


int main() {

    try {

        int x = 10, y = 0;

        if (y == 0) {

            throw runtime_error("Division by zero error!");

        }

        cout << x / y;

    }

    catch (runtime_error &e) {

        cout << "Exception caught: " << e.what() << endl;

    }

    return 0;

}


Output:
Exception caught: Division by zero error!


In C++, the e.what() method is used with exceptions that are derived from the standard exception class std::exception.

What it does

  • std::exception defines a virtual function what() that returns a C-style string (const char*) describing the error.
  • When you catch an exception object (like std::runtime_error, std::out_of_range, etc.), calling e.what() gives you a human-readable message about what went wrong.


In C++, array index out-of-bounds occurs when you try to access an element outside the valid range of an array.

In C++, the symbol || is the logical OR operator.

    It evaluates two boolean expressions (conditions).

    The result is true if at least one of the conditions is true.

    The result is false only if both conditions are false.


Always catch exceptions by reference (usually const &) to:

    Avoid object slicing.

    Preserve polymorphic behavior (what() works correctly for derived classes).

    Improve performance (no extra copy).


Microsoft Copilot

Threatening Dream

dread: causing fear

gambit: a thing that somebody does, or something that somebody says at the beginning of a situation or conversation, that is intended to give them some advantage

Monomaniacal is an adjective describing an obsessive, fanatical, or extreme preoccupation with one single subject, idea, or cause to the exclusion of all others.

cram (for something) (North American English, informal or British English, old-fashioned) to learn a lot of things in a short time, in preparation for an exam

perilous: very dangerous

Combinatorial refers to the branch of mathematics (combinatorics) concerned with counting, arranging, and selecting discrete, finite elements.

nerd: ​a person who is boring, stupid and not fashionable

revert: to reply

nonchalance: ​a calm and relaxed way of behaving; behavior that gives the impression you are not feeling worried

Bill Gates "Source Code"

Online Dictionaries Used:

hk.dictionary.search.yahoo.com

www.oxfordlearnersdictionaries.com

Google AI overview

Osiris, God of Afterlife

Who Osiris Was

  • Osiris started as a local fertility god in Lower Egypt (Busiris).
  • By around 2400 BCE, he became both:
    • God of fertility (life, crops, growth).
    • God of the dead (embodiment of the deceased king).
  • Egyptian kingship tied into this:
    • The dead king became Osiris.
    • The living king was Horus, Osiris’s son.
    • Isis was Osiris’s wife and Horus’s mother.
    • Seth was Osiris’s brother and murderer.

歐西里斯是誰

  • 歐西里斯最初是下埃及布西里斯的地方生育神。
  • 約在西元前2400年,他同時成為:
    • 生育之神(掌管生命、農作物、成長)。
    • 死亡之神(象徵已逝的國王)。
  • 埃及王權與此結合:
    • 已逝的國王化為歐西里斯。
    • 在世的國王是荷魯斯,歐西里斯之子。
    • 伊西斯是歐西里斯的妻子,也是荷魯斯的母親。
    • 賽特是歐西里斯的兄弟與殺害者。

The Myth of Osiris

  • According to Plutarch, Seth killed Osiris, cut his body into 14 pieces, and scattered them across Egypt.
  • Isis and Nephthys found and buried the pieces (except the phallus), reviving Osiris.
  • Osiris then ruled the underworld as judge of the dead.
  • Horus fought Seth, avenged his father, and became king of Egypt.

歐西里斯的神話

  • 根據希臘作家普魯塔克的記載,賽特殺害歐西里斯,將其屍體切成十四塊並散佈埃及各地。
  • 伊西斯與其姊妹奈芙蒂斯找回並埋葬了所有部分(除了陽具),使歐西里斯復生。
  • 從此歐西里斯成為冥界的統治者與審判者。
  • 荷魯斯擊敗賽特,為父報仇,並成為埃及的新王。

Osiris’s Role in Life and Death

  • Osiris wasn’t just ruler of the dead—he symbolized life itself:
    • Fertility of crops.
    • The Nile’s annual flood.
  • Around 2000 BCE, Egyptians believed all people became linked with Osiris at death, not just kings.
  • This didn’t mean resurrection, but renewal of life in the afterlife and through descendants.

歐西里斯在生命與死亡中的角色

  • 歐西里斯不僅是死後的統治者,他象徵著生命本身
    • 農作物的肥沃。
    • 尼羅河的年度氾濫。
  • 約在西元前2000年,埃及人相信所有人死後都與歐西里斯相連,而不僅僅是國王。
  • 這並不意味著復活,而是生命的更新,在來世與後代中延續。

Worship and Festivals

  • Osiris’s cult spread widely, merging with other fertility and underworld gods.
  • Festivals in the Middle Kingdom (1938–1630 BCE) included:
    • Processions and night rituals at Abydos.
    • Public participation and burials along the processional road.
  • Annual festivals reenacted Osiris’s fate:
    • “Osiris gardens” were made—molds shaped like Osiris, filled with Nile soil and grain.
    • Sprouting plants symbolized Osiris’s strength and renewal.

崇拜與祭典

  • 歐西里斯的信仰廣泛傳播,並與其他生育與冥界神明融合。
  • 中王國時期(西元前1938–1630年)的祭典包括:
    • 在阿拜多斯舉行的遊行與夜間儀式。
    • 民眾可參與,並在遊行道路旁埋葬或立紀念碑。
  • 每年祭典重演歐西里斯的命運:
    • 建造「歐西里斯花園」—— 歐西里斯形狀的模具,填入尼羅河水與穀物。
    • 穀物萌芽象徵歐西里斯的力量與更新。

Later Connections

  • At Memphis, Osiris was linked with the sacred bull Apis → Osiris-Apis, later becoming Serapis in Hellenistic times.
  • Greeks and Romans connected him with Dionysus.
  • He was also identified with Soker, another god of the dead.

後期的聯繫

  • 在孟菲斯,歐西里斯與神聖公牛阿比斯結合 → 奧西里斯-阿比斯,後來演變為希臘化時期的塞拉比斯
  • 希臘與羅馬人將歐西里斯與酒神狄奧尼索斯相連。
  • 歐西里斯也與孟菲斯的死神索克同化。

Depictions

  • Oldest images date to ~2300 BCE.
  • In the New Kingdom (1539–1075 BCE), Osiris was shown as:
    • A mummy with arms crossed.
    • Holding a crook and flail (symbols of kingship).
    • Wearing the atef crown (white crown of Upper Egypt + two ostrich feathers).

歐西里斯的形象

  • 最早的形象約在西元前2300年。
  • 新王國時期(西元前1539–1075年),歐西里斯被描繪為:
    • 木乃伊,雙臂交叉於胸前。
    • 一手持牧杖,一手持鞭。
    • 頭戴阿特夫冠(上埃及白冠加兩根鴕鳥羽毛)。


Original Information: https://www.britannica.com/topic/Osiris-Egyptian-god

Summarized, simplified and translated with Microsoft Copilot and edited

2026年1月22日星期四

Exposure

在手動模式 (Manual Mode) 下,曝光補償 (Exposure Compensation) 功能通常不會直接使用,因為您完全控制光圈、快門和 ISO。

〈有牌爛仔〉

雙十暴動是1956年10月10至12日間在香港九龍及荃灣等地發生的一次騷亂。事件的導火線是徙置事務處職員在中華民國國慶10月10日移除懸掛在李鄭屋徙置區的中華民國國旗和大型「雙十」徽牌。

騷動衝着國共力量在港的矛盾,由雙十掛國旗的糾紛觸發,再引來連串駭人的暴力事件。衝突結果帶來六十人死、四百四十三人傷。

Grammar in Use

Wrong: When did this bridge being built?

Correct: When was this bridge built?

Interviews

whisk somebody/something + adv./prep. to take somebody/something somewhere very quickly and suddenly

fabled: ​famous and often talked about, but rarely seen

A DEC computer refers to machines made by the Digital Equipment Corporation (DEC), a pioneering American company famous for revolutionizing computing with affordable minicomputers.

cling: to hold on tightly to somebody/something

"Bonneville" refers to a significant early programming job Bill Gates and Paul Allen had for the Bonneville Power Administration (BPA) in North Bonneville, Washington, where they debugged software for the Pacific Northwest's electrical grid control system for defense contractor Thompson Ramo Wooldridge (TRW).

awed: showing or feeling respect and slight fear; extremely impressed by somebody/something

bask (in something) to enjoy sitting or lying in the heat or light of something, especially the sun

hone: to develop and improve something, especially a skill, over a period of time

veer: to change direction suddenly

angst: a feeling of great worry about a situation, or about your life

Plymouth was a popular American car brand by Chrysler, launched in 1928 to offer affordable cars against Ford and Chevy, becoming known for reliable models like the Valiant and iconic muscle cars.


Bill Gates "Source Code"

Online Dictionaries Used:

hk.dictionary.search.yahoo.com

www.oxfordlearnersdictionaries.com

Google AI overview