summaryrefslogtreecommitdiffstats
path: root/c++/examples/create.cpp
diff options
context:
space:
mode:
authorBinh-Minh Ribler <bmribler@hdfgroup.org>2003-06-25 17:25:11 (GMT)
committerBinh-Minh Ribler <bmribler@hdfgroup.org>2003-06-25 17:25:11 (GMT)
commitfa77b6691e218c49163f477c84fb8664fb5cda8b (patch)
treec2007e35ae40e79718b3b16146a2f0bf2a149818 /c++/examples/create.cpp
parentc9f162a58c26355b70724b211877e2d3ce9c3d94 (diff)
downloadhdf5-fa77b6691e218c49163f477c84fb8664fb5cda8b.zip
hdf5-fa77b6691e218c49163f477c84fb8664fb5cda8b.tar.gz
hdf5-fa77b6691e218c49163f477c84fb8664fb5cda8b.tar.bz2
[svn-r7104] Purpose:
Bug fix Description: Missing returning error for failures occur in C++ examples. Solution: Added "return -1;" when an exception is caught. Also, turned off automatic error printing so that the C++ API will catch and handle the failures. Platforms: SunOS 5.7 (arabica) Linux 2.4 (eirene) IRIX 6.5.11 (modi4)
Diffstat (limited to 'c++/examples/create.cpp')
-rw-r--r--c++/examples/create.cpp78
1 files changed, 44 insertions, 34 deletions
diff --git a/c++/examples/create.cpp b/c++/examples/create.cpp
index 06952f9..06d5d4d 100644
--- a/c++/examples/create.cpp
+++ b/c++/examples/create.cpp
@@ -12,9 +12,9 @@
* access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-//
-// This example writes a dataset to a new HDF5 file.
-//
+/*
+ * This example writes a dataset to a new HDF5 file.
+ */
#include <string>
@@ -37,9 +37,9 @@ const int RANK = 2;
int main (void)
{
- //
- // Data initialization.
- //
+ /*
+ * Data initialization.
+ */
int i, j;
int data[NX][NY]; // buffer for data to write
for (j = 0; j < NX; j++)
@@ -47,50 +47,56 @@ int main (void)
for (i = 0; i < NY; i++)
data[j][i] = i + j;
}
- //
- // 0 1 2 3 4 5
- // 1 2 3 4 5 6
- // 2 3 4 5 6 7
- // 3 4 5 6 7 8
- // 4 5 6 7 8 9
- //
+ /*
+ * 0 1 2 3 4 5
+ * 1 2 3 4 5 6
+ * 2 3 4 5 6 7
+ * 3 4 5 6 7 8
+ * 4 5 6 7 8 9
+ */
// Try block to detect exceptions raised by any of the calls inside it
try
{
- //
- // Create a new file using H5F_ACC_TRUNC access,
- // default file creation properties, and default file
- // access properties.
- //
+ /*
+ * Turn off the auto-printing when failure occurs so that we can
+ * handle the errors appropriately
+ */
+ Exception::dontPrint();
+
+ /*
+ * Create a new file using H5F_ACC_TRUNC access,
+ * default file creation properties, and default file
+ * access properties.
+ */
H5File file( FILE_NAME, H5F_ACC_TRUNC );
- //
- // Define the size of the array and create the data space for fixed
- // size dataset.
- //
+ /*
+ * Define the size of the array and create the data space for fixed
+ * size dataset.
+ */
hsize_t dimsf[2]; // dataset dimensions
dimsf[0] = NX;
dimsf[1] = NY;
DataSpace dataspace( RANK, dimsf );
- //
- // Define datatype for the data in the file.
- // We will store little endian INT numbers.
- //
+ /*
+ * Define datatype for the data in the file.
+ * We will store little endian INT numbers.
+ */
IntType datatype( PredType::NATIVE_INT );
datatype.setOrder( H5T_ORDER_LE );
- //
- // Create a new dataset within the file using defined dataspace and
- // datatype and default dataset creation properties.
- //
+ /*
+ * Create a new dataset within the file using defined dataspace and
+ * datatype and default dataset creation properties.
+ */
DataSet dataset = file.createDataSet( DATASET_NAME, datatype, dataspace );
- //
- // Write the data to the dataset using default memory space, file
- // space, and transfer properties.
- //
+ /*
+ * Write the data to the dataset using default memory space, file
+ * space, and transfer properties.
+ */
dataset.write( data, PredType::NATIVE_INT );
} // end of try block
@@ -98,24 +104,28 @@ int main (void)
catch( FileIException error )
{
error.printError();
+ return -1;
}
// catch failure caused by the DataSet operations
catch( DataSetIException error )
{
error.printError();
+ return -1;
}
// catch failure caused by the DataSpace operations
catch( DataSpaceIException error )
{
error.printError();
+ return -1;
}
// catch failure caused by the DataSpace operations
catch( DataTypeIException error )
{
error.printError();
+ return -1;
}
return 0; // successfully terminated