forked from epics-base/epics-base
-
Notifications
You must be signed in to change notification settings - Fork 2
Convert RecSup function possible exceptions to dbAccess error codes #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
lerwys
wants to merge
2
commits into
mdavidsaver:vfield
Choose a base branch
from
lerwys:vfield
base: vfield
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/*************************************************************************\ | ||
* Copyright (c) 2021 Lucas Russo | ||
* SPDX-License-Identifier: EPICS | ||
* EPICS BASE is distributed subject to a Software License Agreement found | ||
* in file LICENSE that is included with this distribution. | ||
\*************************************************************************/ | ||
|
||
#include <stdexcept> | ||
|
||
#include "recSup.h" | ||
#include "dbAccessDefs.h" | ||
#include "errlog.h" | ||
#include "dbAccessNoThrow.h" | ||
|
||
/* | ||
* Maps possible excpetions to DB error codes. Using the | ||
* "exception dispatcher" pattern. | ||
*/ | ||
inline long dbExceptionToLong() | ||
{ | ||
try { | ||
throw; | ||
} | ||
catch (std::exception& e) { | ||
errlogPrintf("dbExceptionToLong: Unhandled exception %s: %s\n", | ||
typeid(e).name(), e.what()); | ||
return S_db_errArg; | ||
} | ||
} | ||
|
||
/* | ||
* Pseudo variadic templates for use without C++11 features | ||
*/ | ||
|
||
template <typename F, typename T1, typename T2> | ||
long dbRecSupNoThrowWrapper(F f, T1 t1, T2 t2) { | ||
try { | ||
return f(t1, t2); | ||
} | ||
catch(...){ | ||
return dbExceptionToLong(); | ||
} | ||
} | ||
|
||
/* | ||
* Wraps all RecordSupport functions from throwable functions to no-throwable ones, | ||
* without using C++11 features | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, this does give a good example of why I didn't do this initially. For the moment, let's only add wrappers as they used. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, sounds good. |
||
* | ||
* For use with C code | ||
*/ | ||
|
||
long dbRecSupGetVFieldNoThrow(rset *prset, struct dbAddr *paddr, struct VField *vfield) | ||
{ | ||
return dbRecSupNoThrowWrapper(prset->get_vfield, paddr, vfield); | ||
} | ||
|
||
long dbRecSupPutVFieldNoThrow(rset *prset, struct dbAddr *paddr, const struct VField *vfield) | ||
{ | ||
return dbRecSupNoThrowWrapper(prset->put_vfield, paddr, vfield); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/*************************************************************************\ | ||
* Copyright (c) 2021 Lucas Russo | ||
* SPDX-License-Identifier: EPICS | ||
* EPICS BASE is distributed subject to a Software License Agreement found | ||
* in file LICENSE that is included with this distribution. | ||
\*************************************************************************/ | ||
|
||
#ifndef INC_dbAccessNoThrow_H | ||
#define INC_dbAccessNoThrow_H | ||
|
||
#include <dbCoreAPI.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
DBCORE_API long dbRecSupGetVFieldNoThrow(rset *prset, | ||
struct dbAddr *paddr, struct VField *vfield); | ||
DBCORE_API long dbRecSupPutVFieldNoThrow(rset *prset, | ||
struct dbAddr *paddr, const struct VField *vfield); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* INC_dbAccessNoThrow_H */ |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there is much value in translating specific exceptions.
It might be more useful to print the specific exception type
typeid(e).name()
along withe.what()
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Is S_db_errArg a good error for this general "unhandled exception" case?