mirror of
https://gitee.com/beecue/fastbee.git
synced 2025-12-19 17:35:54 +08:00
添加智能灯固件代码
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
idf_component_register(SRCS "exception_example_main.cpp"
|
||||
INCLUDE_DIRS ".")
|
||||
@@ -0,0 +1,4 @@
|
||||
#
|
||||
# "main" pseudo-component makefile.
|
||||
#
|
||||
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
|
||||
@@ -0,0 +1,56 @@
|
||||
/* C++ exception handling example
|
||||
|
||||
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||
|
||||
Unless required by applicable law or agreed to in writing, this
|
||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using std::runtime_error;
|
||||
|
||||
/* A simple class which may throw an exception from constructor */
|
||||
class Throwing
|
||||
{
|
||||
public:
|
||||
Throwing(int arg)
|
||||
: m_arg(arg)
|
||||
{
|
||||
cout << "In constructor, arg=" << arg << endl;
|
||||
if (arg == 0) {
|
||||
throw runtime_error("Exception in constructor");
|
||||
}
|
||||
}
|
||||
|
||||
~Throwing()
|
||||
{
|
||||
cout << "In destructor, m_arg=" << m_arg << endl;
|
||||
}
|
||||
|
||||
protected:
|
||||
int m_arg;
|
||||
};
|
||||
|
||||
/* Inside .cpp file, app_main function must be declared with C linkage */
|
||||
extern "C" void app_main(void)
|
||||
{
|
||||
cout << "app_main starting" << endl;
|
||||
|
||||
try {
|
||||
/* This will succeed */
|
||||
Throwing obj1(42);
|
||||
|
||||
/* This will throw an exception */
|
||||
Throwing obj2(0);
|
||||
|
||||
cout << "This will not be printed" << endl;
|
||||
} catch (const runtime_error &e) {
|
||||
cout << "Exception caught: " << e.what() << endl;
|
||||
}
|
||||
|
||||
cout << "app_main done" << endl;
|
||||
}
|
||||
Reference in New Issue
Block a user