1 |
|
#include <util.hpp> |
2 |
|
|
3 |
|
namespace hmlp |
4 |
|
{ |
5 |
|
|
6 |
|
/** |
7 |
|
* \breif Translate hmlpError_t to error string. |
8 |
|
*/ |
9 |
|
const char* getErrorString( hmlpError_t error ) |
10 |
|
{ |
11 |
|
switch ( error ) |
12 |
|
{ |
13 |
|
case HMLP_ERROR_SUCCESS: |
14 |
|
return "HMLP_ERROR_SUCCESS"; |
15 |
|
case HMLP_ERROR_ALLOC_FAILED: |
16 |
|
return "HMLP_ERROR_ALLOC_FAILED"; |
17 |
|
case HMLP_ERROR_INVALID_VALUE: |
18 |
|
return "HMLP_ERROR_INVALID_VALUE"; |
19 |
|
case HMLP_ERROR_EXECUTION_FAILED: |
20 |
|
return "HMLP_ERROR_EXECUTION_FAILED"; |
21 |
|
case HMLP_ERROR_NOT_SUPPORTED: |
22 |
|
return "HMLP_ERROR_NOT_SUPPORTED"; |
23 |
|
case HMLP_ERROR_INTERNAL_ERROR: |
24 |
|
return "HMLP_ERROR_INTERNAL_ERROR"; |
25 |
|
} |
26 |
|
return "<unknown>"; |
27 |
|
}; |
28 |
|
|
29 |
|
|
30 |
|
/** |
31 |
|
* \breif Handling runtime error with information. |
32 |
|
*/ |
33 |
|
void handleError( hmlpError_t error, const char* file, int line ) |
34 |
|
{ |
35 |
|
if ( error == HMLP_ERROR_SUCCESS ) return; |
36 |
|
/** Otherwise, handle the error and provide information. */ |
37 |
|
printf( "Error: %s in %s at line %d\n", getErrorString( error ), file, line ); |
38 |
|
throw std::invalid_argument( "Program encounters hmlp error." ); |
39 |
|
}; |
40 |
|
|
41 |
|
}; /* end namespace hmlp */ |