Foundation Classes - Inherited Standard_Failure from std::exception (#984)

First patch in iterative renovation of exceptions.

- Simplify exception classes to be container of data only.
- Removed redundant inclusion of <Standard_Type.hxx> in various header files across the project.
- Removed Set methods for failure and its define template.
- Removed Raise and Rerise static methods.
- Remove Instance and Throw methods
- Deprecated getting message with old approach, and moving to what()
- Update ErrorHandler to handle only specific list of exceptions.
This commit is contained in:
Pasukhin Dmitry
2026-01-07 12:22:32 +00:00
committed by GitHub
parent 6c6f2ceb41
commit e1d36343e4
174 changed files with 590 additions and 668 deletions
+179
View File
@@ -0,0 +1,179 @@
#!/usr/bin/env python3
"""
Script to migrate Standard_*::Raise() calls to throw Standard_*() statements.
Pattern: Standard_SomeException::Raise("message") -> throw Standard_SomeException("message")
Also removes unnecessary 'return;' or 'return "";' statements after throw.
Usage:
python3 migrate_raise_to_throw.py [--dry-run]
"""
import re
import os
import sys
import argparse
# Pattern to match Standard_*::Raise calls (single or multi-line)
# Captures: (ExceptionType, arguments)
RAISE_PATTERN = re.compile(
r'(Standard_\w+)::Raise\s*\(\s*([^;]*?)\s*\)\s*;',
re.DOTALL
)
# Pattern to match 'return "";' or 'return;' that might follow a throw
RETURN_AFTER_THROW = re.compile(
r'(throw\s+Standard_\w+\s*\([^)]*\)\s*;)\s*\n(\s*)(return\s*"?"?\s*;)',
re.DOTALL
)
# Special case for #define YY_FATAL_ERROR
YY_FATAL_PATTERN = re.compile(
r'#define\s+YY_FATAL_ERROR\s*\(\s*msg\s*\)\s*Standard_Failure::Raise\s*\(\s*msg\s*\)\s*;'
)
# Patterns to skip (method definitions, not static calls)
SKIP_PATTERNS = [
r'void\s+Standard_\w+::Raise\s*\(', # Method definitions
r'//.*Standard_\w+::Raise', # Comments
]
def find_occt_root():
"""Find OCCT root directory by looking for src/ directory."""
script_dir = os.path.dirname(os.path.abspath(__file__))
# Navigate up from adm/scripts/migration_800 to root
root = os.path.dirname(os.path.dirname(os.path.dirname(script_dir)))
if os.path.isdir(os.path.join(root, 'src')):
return root
# Try current directory
if os.path.isdir('src'):
return os.getcwd()
return None
def should_skip_line(line):
"""Check if line should be skipped (method definition or comment)."""
for pattern in SKIP_PATTERNS:
if re.search(pattern, line):
return True
return False
def find_files_with_raise(src_dir):
"""Find all .cxx and .hxx files containing Standard_*::Raise calls."""
files_to_process = []
for root, dirs, files in os.walk(src_dir):
for filename in files:
if filename.endswith(('.cxx', '.hxx', '.lex')):
filepath = os.path.join(root, filename)
try:
with open(filepath, 'r', encoding='utf-8', errors='replace') as f:
content = f.read()
# Check if file contains Raise pattern
if RAISE_PATTERN.search(content) or YY_FATAL_PATTERN.search(content):
# Verify it's not just method definitions
lines_with_raise = [line for line in content.split('\n')
if 'Standard_' in line and '::Raise' in line]
has_static_calls = any(not should_skip_line(line)
for line in lines_with_raise)
if has_static_calls:
files_to_process.append(filepath)
except Exception as e:
print(f" Warning: Could not read {filepath}: {e}")
return files_to_process
def process_file(filepath, dry_run=False):
"""Process a single file to replace Raise calls with throw."""
with open(filepath, 'r', encoding='utf-8', errors='replace') as f:
content = f.read()
original_content = content
changes = []
# Handle special case for YY_FATAL_ERROR macro
if YY_FATAL_PATTERN.search(content):
content = YY_FATAL_PATTERN.sub(
'#define YY_FATAL_ERROR(msg) throw Standard_Failure(msg);',
content
)
changes.append("YY_FATAL_ERROR macro")
# Replace Standard_*::Raise(...) with throw Standard_*(...)
def replace_raise(match):
exception_type = match.group(1)
args = match.group(2).strip()
# Clean up multi-line arguments
args = ' '.join(args.split())
changes.append(f"{exception_type}::Raise -> throw")
return f'throw {exception_type}({args});'
content = RAISE_PATTERN.sub(replace_raise, content)
# Remove 'return "";' or 'return;' that follows a throw
def remove_return_after_throw(match):
throw_stmt = match.group(1)
changes.append("removed return after throw")
return throw_stmt
content = RETURN_AFTER_THROW.sub(remove_return_after_throw, content)
if content != original_content:
if not dry_run:
with open(filepath, 'w', encoding='utf-8') as f:
f.write(content)
return changes
return None
def main():
parser = argparse.ArgumentParser(
description='Migrate Standard_*::Raise() to throw Standard_*()'
)
parser.add_argument('--dry-run', action='store_true',
help='Show what would be changed without modifying files')
args = parser.parse_args()
occt_root = find_occt_root()
if not occt_root:
print("Error: Could not find OCCT root directory")
sys.exit(1)
src_dir = os.path.join(occt_root, 'src')
print(f"OCCT root: {occt_root}")
print(f"Scanning: {src_dir}")
print("=" * 60)
if args.dry_run:
print("DRY RUN - no files will be modified")
print("=" * 60)
# Find files to process
files = find_files_with_raise(src_dir)
print(f"Found {len(files)} files with Standard_*::Raise calls")
print("=" * 60)
modified_count = 0
for filepath in sorted(files):
rel_path = os.path.relpath(filepath, occt_root)
changes = process_file(filepath, args.dry_run)
if changes:
modified_count += 1
action = "WOULD MODIFY" if args.dry_run else "MODIFIED"
print(f" {action}: {rel_path}")
for change in changes:
print(f" - {change}")
print("=" * 60)
action = "Would modify" if args.dry_run else "Modified"
print(f"{action} {modified_count} files")
if __name__ == "__main__":
main()
@@ -855,7 +855,7 @@ int main (int argc, char* argv[])
}
catch (const Standard_Failure& theFailure)
{
std::cerr << "Error " + theFailure.DynamicType()->Name() << " [" << theFailure.GetMessageString() << "]\n";
std::cerr << "Error " << theFailure.ExceptionType() << " [" << theFailure.what() << "]\n";
}
return 1;
}
@@ -65,8 +65,7 @@ void BinDrivers_DocumentRetrievalDriver::ReadShapeSection(
catch (Standard_Failure const& anException)
{
const TCollection_ExtendedString aMethStr("BinDrivers_DocumentRetrievalDriver: ");
myMsgDriver->Send(aMethStr + "error of Shape Section " + anException.GetMessageString(),
Message_Fail);
myMsgDriver->Send(aMethStr + "error of Shape Section " + anException.what(), Message_Fail);
}
}
}
@@ -189,7 +189,7 @@ void BinDrivers_DocumentStorageDriver::WriteShapeSection(BinLDrivers_DocumentSec
catch (Standard_Failure const& anException)
{
TCollection_ExtendedString anErrorStr("BinDrivers_DocumentStorageDriver, Shape Section :");
myMsgDriver->Send(anErrorStr + anException.GetMessageString(), Message_Fail);
myMsgDriver->Send(anErrorStr + anException.what(), Message_Fail);
}
}
@@ -31,7 +31,7 @@ static void CAUGHT(const Standard_Failure& theException,
const TCollection_ExtendedString& what)
{
status += what;
status += theException.GetMessageString();
status += theException.what();
}
CDF_StoreList::CDF_StoreList(const occ::handle<CDM_Document>& aDocument)
@@ -17,7 +17,6 @@
#ifndef _PCDM_DriverError_HeaderFile
#define _PCDM_DriverError_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_DefineException.hxx>
#include <Standard_SStream.hxx>
#include <Standard_Failure.hxx>
@@ -269,7 +269,7 @@ PCDM_ReaderStatus TDocStd_Application::Open(const TCollection_ExtendedString&
// Standard_SStream aMsg;
// aMsg << Standard_Failure::Caught() << std::endl;
// std::cout << "TDocStd_Application::Open(): " << aMsg.rdbuf()->str() << std::endl;
TCollection_ExtendedString aString(anException.GetMessageString());
TCollection_ExtendedString aString(anException.what());
MessageDriver()->Send(aString.ToExtString(), Message_Fail);
}
}
@@ -306,7 +306,7 @@ PCDM_ReaderStatus TDocStd_Application::Open(Standard_IStream&
{
if (!MessageDriver().IsNull())
{
TCollection_ExtendedString aFailureMessage(anException.GetMessageString());
TCollection_ExtendedString aFailureMessage(anException.what());
MessageDriver()->Send(aFailureMessage.ToExtString(), Message_Fail);
}
}
@@ -345,7 +345,7 @@ PCDM_StoreStatus TDocStd_Application::SaveAs(const occ::handle<TDocStd_Document>
{
if (!MessageDriver().IsNull())
{
TCollection_ExtendedString aString(anException.GetMessageString());
TCollection_ExtendedString aString(anException.what());
MessageDriver()->Send(aString.ToExtString(), Message_Fail);
}
}
@@ -388,7 +388,7 @@ PCDM_StoreStatus TDocStd_Application::SaveAs(const occ::handle<TDocStd_Document>
{
if (!MessageDriver().IsNull())
{
TCollection_ExtendedString aString(anException.GetMessageString());
TCollection_ExtendedString aString(anException.what());
MessageDriver()->Send(aString.ToExtString(), Message_Fail);
}
}
@@ -413,7 +413,7 @@ PCDM_StoreStatus TDocStd_Application::Save(const occ::handle<TDocStd_Document>&
{
if (!MessageDriver().IsNull())
{
TCollection_ExtendedString aString(anException.GetMessageString());
TCollection_ExtendedString aString(anException.what());
MessageDriver()->Send(aString.ToExtString(), Message_Fail);
}
}
@@ -463,7 +463,7 @@ PCDM_StoreStatus TDocStd_Application::SaveAs(const occ::handle<TDocStd_Document>
{
if (!MessageDriver().IsNull())
{
TCollection_ExtendedString aString(anException.GetMessageString());
TCollection_ExtendedString aString(anException.what());
MessageDriver()->Send(aString.ToExtString(), Message_Fail);
}
}
@@ -513,7 +513,7 @@ PCDM_StoreStatus TDocStd_Application::SaveAs(const occ::handle<TDocStd_Document>
{
if (!MessageDriver().IsNull())
{
TCollection_ExtendedString aString(anException.GetMessageString());
TCollection_ExtendedString aString(anException.what());
MessageDriver()->Send(aString.ToExtString(), Message_Fail);
}
}
@@ -539,7 +539,7 @@ PCDM_StoreStatus TDocStd_Application::Save(const occ::handle<TDocStd_Document>&
{
if (!MessageDriver().IsNull())
{
TCollection_ExtendedString aString(anException.GetMessageString());
TCollection_ExtendedString aString(anException.what());
MessageDriver()->Send(aString.ToExtString(), Message_Fail);
}
}
@@ -117,7 +117,7 @@ bool TObj_Application::LoadDocument(const TCollection_ExtendedString& theSourceF
catch (Standard_Failure const& anException)
{
#ifdef OCCT_DEBUG
ErrorMessage(Message_Msg("TObj_Appl_Exception") << anException.GetMessageString());
ErrorMessage(Message_Msg("TObj_Appl_Exception") << anException.what());
#endif
(void)anException;
}
@@ -148,7 +148,7 @@ bool TObj_Application::LoadDocument(Standard_IStream& theIStream,
catch (Standard_Failure const& anException)
{
#ifdef OCCT_DEBUG
ErrorMessage(Message_Msg("TObj_Appl_Exception") << anException.GetMessageString());
ErrorMessage(Message_Msg("TObj_Appl_Exception") << anException.what());
#endif
(void)anException;
}
@@ -173,7 +173,7 @@ bool TObj_Model::Load(const TCollection_ExtendedString& theFile)
catch (Standard_Failure const& anException)
{
#ifdef OCCT_DEBUG
TCollection_ExtendedString aString(anException.DynamicType()->Name());
TCollection_ExtendedString aString(anException.ExceptionType());
aString = aString + ": " + anException.GetMessageString();
Messenger()->Send(Message_Msg("TObj_Appl_Exception") << aString);
#endif
@@ -270,8 +270,7 @@ bool TObj_Model::Load(Standard_IStream& theIStream)
catch (Standard_Failure const& anException)
{
#ifdef OCCT_DEBUG
TCollection_ExtendedString aString(anException.DynamicType()->Name());
aString = aString + ": " + anException.GetMessageString();
TCollection_ExtendedString aString(anException.what());
Messenger()->Send(Message_Msg("TObj_Appl_Exception") << aString);
#endif
(void)anException;
@@ -487,7 +487,7 @@ void XmlLDrivers_DocumentRetrievalDriver::ReadFromDomDocument(
}
catch (Standard_Failure const& anException)
{
TCollection_ExtendedString anErrorString(anException.GetMessageString());
TCollection_ExtendedString anErrorString(anException.what());
aMsgDriver->Send(anErrorString.ToExtString(), Message_Fail);
}
if (!aPS.More())
@@ -336,7 +336,7 @@ bool XmlLDrivers_DocumentStorageDriver::WriteToDomDocument(
{
SetIsError(true);
SetStoreStatus(PCDM_SS_Failure);
TCollection_ExtendedString anErrorString(anException.GetMessageString());
TCollection_ExtendedString anErrorString(anException.what());
aMessageDriver->Send(anErrorString.ToExtString(), Message_Fail);
}
}
@@ -605,7 +605,7 @@ int RWObj_Reader::triangulatePolygon(const NCollection_Array1<int>& theIndices)
catch (Standard_Failure const& theFailure)
{
Message::SendWarning(TCollection_AsciiString("Error: exception raised during polygon split\n[")
+ theFailure.GetMessageString() + "]");
+ theFailure.what() + "]");
}
return triangulatePolygonFan(theIndices);
}
@@ -122,7 +122,7 @@ IFSelect_ReturnStatus STEPControl_Reader::ReadFile(const char* filename)
{
Message_Messenger::StreamBuffer sout = Message::SendInfo();
sout << " **** Interruption ReadFile par Exception : ****\n";
sout << anException.GetMessageString();
sout << anException.what();
sout << "\n Abandon" << std::endl;
status = IFSelect_RetFail;
}
@@ -166,7 +166,7 @@ IFSelect_ReturnStatus STEPControl_Reader::ReadFile(const char* file
{
Message_Messenger::StreamBuffer sout = Message::SendInfo();
sout << " **** Interruption ReadFile par Exception : ****\n";
sout << anException.GetMessageString();
sout << anException.what();
sout << "\n Abandon" << std::endl;
status = IFSelect_RetFail;
}
@@ -209,7 +209,7 @@ IFSelect_ReturnStatus STEPControl_Reader::ReadStream(const char* theName, std::i
{
Message_Messenger::StreamBuffer sout = Message::SendInfo();
sout << " **** Interruption ReadFile par Exception : ****\n";
sout << anException.GetMessageString();
sout << anException.what();
sout << "\n Abandon" << std::endl;
status = IFSelect_RetFail;
}
@@ -254,7 +254,7 @@ IFSelect_ReturnStatus STEPControl_Reader::ReadStream(const char* th
{
Message_Messenger::StreamBuffer sout = Message::SendInfo();
sout << " **** Interruption ReadFile par Exception : ****\n";
sout << anException.GetMessageString();
sout << anException.what();
sout << "\n Abandon" << std::endl;
status = IFSelect_RetFail;
}
@@ -94,7 +94,7 @@ void StepData_StepReaderTool::Prepare(const bool optim)
{
Message_Messenger::StreamBuffer sout = Message::SendInfo();
sout << " Exception Raised during Preparation :\n";
sout << anException.GetMessageString();
sout << anException.what();
sout << "\n Now, trying to continue, but with presomption of failure\n";
}
}
@@ -749,7 +749,7 @@ void StepToTopoDS_Builder::Init(const occ::handle<StepShape_GeometricSet>& GC
{
Message_Messenger::StreamBuffer sout = TP->Messenger()->SendInfo();
sout << "StepToTopoDS, GeometricSet, elem " << i << " of " << nbElem << ": exception ";
sout << anException.GetMessageString() << std::endl;
sout << anException.what() << std::endl;
}
if (!aGeomCrv.IsNull())
{
@@ -472,7 +472,7 @@ void TopoDSToStep_MakeStepFace::Init(const TopoDS_Face&
}
catch (Standard_Failure const& theFailure)
{
FP->AddFail(errShape, theFailure.GetMessageString());
FP->AddFail(errShape, theFailure.what());
myError = TopoDSToStep_FaceOther;
done = false;
}
@@ -17,6 +17,7 @@
#define _RWStl_Reader_HeaderFile
#include <gp_XYZ.hxx>
#include <Standard_Type.hxx>
#include <Standard_ReadLineBuffer.hxx>
#include <Standard_IStream.hxx>
@@ -144,8 +144,7 @@ bool RWMesh_MaterialMap::copyFileTo(const TCollection_AsciiString& theFileSrc,
}
catch (Standard_Failure const& theException)
{
Message::SendFail(TCollection_AsciiString("Failed to copy file\n")
+ theException.GetMessageString());
Message::SendFail(TCollection_AsciiString("Failed to copy file\n") + theException.what());
return false;
}
}
@@ -182,7 +182,7 @@ IFSelect_ReturnStatus IFSelect_WorkSession::ReadFile(const char* filename)
{
Message_Messenger::StreamBuffer sout = Message::SendInfo();
sout << " **** ReadFile Interruption by Exception : ****\n";
sout << anException.GetMessageString();
sout << anException.what();
sout << "\n Abandon" << std::endl;
status = IFSelect_RetFail;
}
@@ -221,7 +221,7 @@ IFSelect_ReturnStatus IFSelect_WorkSession::ReadStream(const char* theName,
{
Message_Messenger::StreamBuffer sout = Message::SendInfo();
sout << " **** ReadFile Interruption by Exception : ****\n";
sout << anException.GetMessageString();
sout << anException.what();
sout << "\n Abandon" << std::endl;
status = IFSelect_RetFail;
}
@@ -1187,7 +1187,7 @@ Interface_EntityIterator IFSelect_WorkSession::EvalSelection(
{
Message_Messenger::StreamBuffer sout = Message::SendInfo();
sout << " **** EvalSelection Interrupted by Exception : ****\n";
sout << anException.GetMessageString();
sout << anException.what();
sout << "\n Abandon" << std::endl;
}
errhand = theerrhand;
@@ -1226,7 +1226,7 @@ occ::handle<NCollection_HSequence<occ::handle<Standard_Transient>>> IFSelect_Wor
{
Message_Messenger::StreamBuffer sout = Message::SendInfo();
sout << " **** SelectionResult Interrupted by Exception : ****\n";
sout << anException.GetMessageString();
sout << anException.what();
sout << "\n Abandon" << std::endl;
}
errhand = theerrhand;
@@ -1883,7 +1883,7 @@ void IFSelect_WorkSession::EvaluateFile()
{
Message_Messenger::StreamBuffer sout = Message::SendInfo();
sout << " **** EvaluateFile Interrupted by Exception : ****\n";
sout << anException.GetMessageString();
sout << anException.what();
sout << "\n Abandon" << std::endl;
checks.CCheck(0)->AddFail("Exception Raised -> Abandon");
}
@@ -1968,7 +1968,7 @@ bool IFSelect_WorkSession::SendSplit()
{
Message_Messenger::StreamBuffer sout = Message::SendInfo();
sout << " **** SendSplit Interrupted by Exception : ****\n";
sout << anException.GetMessageString();
sout << anException.what();
sout << "\n Abandon" << std::endl;
checks.CCheck(0)->AddFail("Exception Raised -> Abandon");
}
@@ -2217,7 +2217,7 @@ IFSelect_ReturnStatus IFSelect_WorkSession::SendAll(const char* filename, const
{
Message_Messenger::StreamBuffer sout = Message::SendInfo();
sout << " **** SendAll Interrupted by Exception : ****\n";
sout << anException.GetMessageString();
sout << anException.what();
sout << "\n Abandon" << std::endl;
errhand = theerrhand;
checks.CCheck(0)->AddFail("Exception Raised -> Abandon");
@@ -2270,7 +2270,7 @@ IFSelect_ReturnStatus IFSelect_WorkSession::SendSelected(const char* filename,
{
Message_Messenger::StreamBuffer sout = Message::SendInfo();
sout << " **** SendSelected Interrupted by Exception : ****\n";
sout << anException.GetMessageString();
sout << anException.what();
sout << "\n Abandon" << std::endl;
checks.CCheck(0)->AddFail("Exception Raised -> Abandon");
errhand = theerrhand;
@@ -3371,7 +3371,7 @@ void IFSelect_WorkSession::DumpModel(const int level, Standard_OStream& S)
{
Message_Messenger::StreamBuffer sout = Message::SendInfo();
sout << " **** DumpModel Interrupted by Exception : ****\n";
sout << anException.GetMessageString();
sout << anException.what();
sout << "\n Abandon" << std::endl;
}
}
@@ -3558,7 +3558,7 @@ void IFSelect_WorkSession::EvaluateSelection(const occ::handle<IFSelect_Selectio
catch (Standard_Failure const& anException)
{
sout << " **** EvaluateSelection Interrupted by Exception **** Title\n";
sout << anException.GetMessageString();
sout << anException.what();
sout << "\n Abandon" << std::endl;
}
errhand = theerrhand;
@@ -3600,7 +3600,7 @@ void IFSelect_WorkSession::EvaluateDispatch(const occ::handle<IFSelect_Dispatch>
catch (Standard_Failure const& anException)
{
sout << " **** EvaluateDispatch Interrupted by Exception **** Title\n";
sout << anException.GetMessageString();
sout << anException.what();
sout << "\n Abandon" << std::endl;
}
errhand = theerrhand;
@@ -3694,7 +3694,7 @@ void IFSelect_WorkSession::EvaluateComplete(const int mode) const
catch (Standard_Failure const& anException)
{
sout << " **** EvaluateComplete Interrupted by Exception : ****\n";
sout << anException.GetMessageString();
sout << anException.what();
sout << "\n Abandon" << std::endl;
}
errhand = theerrhand;
@@ -3868,7 +3868,7 @@ void IFSelect_WorkSession::ListEntities(const Interface_EntityIterator& iter,
catch (Standard_Failure const& anException)
{
sout << " **** ListEntities Interrupted by Exception : ****\n";
sout << anException.GetMessageString();
sout << anException.what();
sout << "\n Abandon" << std::endl;
}
}
@@ -17,7 +17,6 @@
#ifndef _Interface_CheckFailure_HeaderFile
#define _Interface_CheckFailure_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_DefineException.hxx>
#include <Standard_SStream.hxx>
#include <Interface_InterfaceError.hxx>
@@ -41,16 +41,16 @@ static int errh = 1;
static void raisecheck(Standard_Failure& theException, occ::handle<Interface_Check>& ach)
{
char mess[100];
Sprintf(mess, "** Exception Raised during Check : %s **", theException.DynamicType()->Name());
Sprintf(mess, "** Exception Raised during Check : %s **", theException.ExceptionType());
ach->AddFail(mess);
#ifdef _WIN32
if (theException.IsKind(STANDARD_TYPE(OSD_Exception)))
if (dynamic_cast<OSD_Exception*>(&theException) != nullptr)
{
#else
if (theException.IsKind(STANDARD_TYPE(OSD_Signal)))
if (dynamic_cast<OSD_Signal*>(&theException) != nullptr)
{
#endif
theException.SetMessageString("System Signal received, check interrupt");
throw theException;
}
}
@@ -343,10 +343,10 @@ void Interface_FileReaderTool::LoadModel(const occ::handle<Interface_InterfaceMo
// clang-format on
#ifdef _WIN32
if (anException.IsKind(STANDARD_TYPE(OSD_Exception)))
if (dynamic_cast<const OSD_Exception*>(&anException) != nullptr)
ierr = 2;
#else
if (anException.IsKind(STANDARD_TYPE(OSD_Signal)))
if (dynamic_cast<const OSD_Signal*>(&anException) != nullptr)
ierr = 2;
#endif
//: abv 03Apr00: anent is actually a previous one: if (anent.IsNull())
@@ -17,7 +17,6 @@
#ifndef _Interface_InterfaceError_HeaderFile
#define _Interface_InterfaceError_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_DefineException.hxx>
#include <Standard_SStream.hxx>
#include <Standard_Failure.hxx>
@@ -17,7 +17,6 @@
#ifndef _Interface_InterfaceMismatch_HeaderFile
#define _Interface_InterfaceMismatch_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_DefineException.hxx>
#include <Standard_SStream.hxx>
#include <Interface_InterfaceError.hxx>
@@ -148,10 +148,14 @@ void MoniTool_CaseData::AddData(const occ::handle<Standard_Transient>& val,
thesubst = 0;
}
void MoniTool_CaseData::AddRaised(const occ::handle<Standard_Failure>& theException,
const char* name)
void MoniTool_CaseData::AddRaised(const Standard_Failure& theException, const char* name)
{
AddData(theException, 1, name);
// Store exception type and message as text (since Standard_Failure is no longer
// Standard_Transient)
TCollection_AsciiString aText(theException.ExceptionType());
aText += ": ";
aText += theException.what();
AddText(aText.ToCString(), name);
}
void MoniTool_CaseData::AddShape(const TopoDS_Shape& sh, const char* name)
@@ -115,9 +115,8 @@ public:
const int kind,
const char* name = "");
//! Adds the currently caught exception
Standard_EXPORT void AddRaised(const occ::handle<Standard_Failure>& theException,
const char* name = "");
//! Adds the currently caught exception (stores exception type and message as text)
Standard_EXPORT void AddRaised(const Standard_Failure& theException, const char* name = "");
//! Adds a Shape (recorded as a HShape)
Standard_EXPORT void AddShape(const TopoDS_Shape& sh, const char* name = "");
@@ -819,7 +819,7 @@ occ::handle<Transfer_Binder> Transfer_ProcessForFinder::Transferring(
binder->AddFail("Transfer stopped by exception raising");
if (thetrace)
{
aSender << " *** Raised : " << anException.GetMessageString() << std::endl;
aSender << " *** Raised : " << anException.what() << std::endl;
StartTrace(binder, start, thelevel - 1, 4);
}
thelevel = oldlev;
@@ -812,7 +812,7 @@ occ::handle<Transfer_Binder> Transfer_ProcessForTransient::Transferring(
binder->AddFail("Transfer stopped by exception raising");
if (thetrace)
{
aSender << " *** Raised : " << anException.GetMessageString() << std::endl;
aSender << " *** Raised : " << anException.what() << std::endl;
StartTrace(binder, start, thelevel - 1, 4);
}
thelevel = oldlev;
@@ -17,7 +17,6 @@
#ifndef _Transfer_TransferDeadLoop_HeaderFile
#define _Transfer_TransferDeadLoop_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_SStream.hxx>
#include <Transfer_TransferFailure.hxx>
@@ -17,7 +17,6 @@
#ifndef _Transfer_TransferFailure_HeaderFile
#define _Transfer_TransferFailure_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_DefineException.hxx>
#include <Standard_SStream.hxx>
#include <Interface_InterfaceError.hxx>
@@ -104,7 +104,7 @@ IFSelect_ReturnStatus XSControl_TransferWriter::TransferWriteTransient(
catch (Standard_Failure const& anException)
{
sout << "**** **** TransferWriteShape, EXCEPTION : ";
sout << anException.GetMessageString();
sout << anException.what();
sout << std::endl;
status = IFSelect_RetFail;
}
@@ -159,7 +159,7 @@ IFSelect_ReturnStatus XSControl_TransferWriter::TransferWriteShape(
catch (Standard_Failure const& anException)
{
sout << "**** **** TransferWriteShape, EXCEPTION : ";
sout << anException.GetMessageString();
sout << anException.what();
sout << std::endl;
status = IFSelect_RetFail;
}
+1 -1
View File
@@ -79,7 +79,7 @@ public:
}
catch (Standard_Failure& anExcept)
{
std::cout << "Failed to evaluate command: " << anExcept.GetMessageString() << std::endl;
std::cout << "Failed to evaluate command: " << anExcept.what() << std::endl;
}
return aRes;
}
@@ -2188,7 +2188,7 @@ static int DNaming_TestSingle(Draw_Interpretor& theDI, int theNb, const char** t
catch (Standard_Failure const& anException)
{
std::cout << "%%%INFO:Error: ::TestSingleSelection failed :";
std::cout << anException.GetMessageString() << std::endl;
std::cout << anException.what() << std::endl;
}
catch (...)
{
@@ -2342,7 +2342,7 @@ static int DNaming_Multiple(Draw_Interpretor& theDI, int theNb, const char** the
catch (Standard_Failure const& anException)
{
std::cout << "%%%INFO:Error: ::TestSingleSelection failed :";
std::cout << anException.GetMessageString() << std::endl;
std::cout << anException.what() << std::endl;
}
catch (...)
{
+1 -1
View File
@@ -43,7 +43,7 @@ Standard_EXPORT const char* DBRep_Set(const char* theNameStr, void* theShapePtr)
}
catch (Standard_Failure const& anException)
{
return anException.GetMessageString();
return anException.what();
}
}
+1 -1
View File
@@ -38,6 +38,6 @@ Standard_EXPORT const char* Draw_Eval(const char* theCommandStr)
}
catch (Standard_Failure const& anException)
{
return anException.GetMessageString();
return anException.what();
}
}
-1
View File
@@ -17,7 +17,6 @@
#ifndef _Draw_Failure_HeaderFile
#define _Draw_Failure_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_DefineException.hxx>
#include <Standard_SStream.hxx>
#include <Standard_Failure.hxx>
+1 -1
View File
@@ -1644,7 +1644,7 @@ bool Init_Appli(HINSTANCE hInst, HINSTANCE hPrevInst, int nShow, HWND& hWndFrame
}
catch (Standard_Failure& anExcept)
{
std::cout << "Failed to initialize Tk: " << anExcept.GetMessageString() << std::endl;
std::cout << "Failed to initialize Tk: " << anExcept.what() << std::endl;
}
Tcl_StaticPackage(interp, "Tk", Tk_Init, (Tcl_PackageInitProc*)NULL);
@@ -54,7 +54,7 @@ Standard_EXPORT const char* DrawTrSurf_Set(const char* theNameStr, void* theHand
}
catch (Standard_Failure const& anException)
{
return anException.GetMessageString();
return anException.what();
}
}
@@ -80,7 +80,7 @@ Standard_EXPORT const char* DrawTrSurf_SetPnt(const char* theNameStr, void* theP
}
catch (Standard_Failure const& anException)
{
return anException.GetMessageString();
return anException.what();
}
}
@@ -101,7 +101,7 @@ Standard_EXPORT const char* DrawTrSurf_SetPnt2d(const char* theNameStr, void* th
}
catch (Standard_Failure const& anException)
{
return anException.GetMessageString();
return anException.what();
}
}
+12 -12
View File
@@ -2097,7 +2097,7 @@ static int OCC6143(Draw_Interpretor& di, int argc, const char** argv)
catch (Standard_Failure const& anException)
{
di << " Caught (";
di << anException.GetMessageString();
di << anException.what();
di << ")... KO\n";
Succes = false;
}
@@ -2134,7 +2134,7 @@ static int OCC6143(Draw_Interpretor& di, int argc, const char** argv)
{
// std::cout << " Caught (" << Standard_Failure::Caught() << ")... KO" << std::endl;
di << " Caught (";
di << anException.GetMessageString();
di << anException.what();
di << ")... KO\n";
Succes = false;
}
@@ -2177,7 +2177,7 @@ static int OCC6143(Draw_Interpretor& di, int argc, const char** argv)
{
// std::cout << " Caught (" << Standard_Failure::Caught() << ")... KO" << std::endl;
di << " Caught (";
di << anException.GetMessageString();
di << anException.what();
di << ")... KO\n";
Succes = false;
}
@@ -2211,7 +2211,7 @@ static int OCC6143(Draw_Interpretor& di, int argc, const char** argv)
{
// std::cout << " Caught (" << Standard_Failure::Caught() << ")... KO" << std::endl;
di << " Caught (";
di << anException.GetMessageString();
di << anException.what();
di << ")... KO\n";
Succes = false;
}
@@ -2248,7 +2248,7 @@ static int OCC6143(Draw_Interpretor& di, int argc, const char** argv)
{
// std::cout << " Caught (" << Standard_Failure::Caught() << ")... KO" << std::endl;
di << " Caught (";
di << anException.GetMessageString();
di << anException.what();
di << ")... KO\n";
Succes = false;
}
@@ -2275,7 +2275,7 @@ static int OCC6143(Draw_Interpretor& di, int argc, const char** argv)
{
// std::cout << " Caught (" << Standard_Failure::Caught() << ")... KO" << std::endl;
di << " Caught (";
di << anException.GetMessageString();
di << anException.what();
di << ")... KO\n";
Succes = false;
}
@@ -2306,7 +2306,7 @@ static int OCC6143(Draw_Interpretor& di, int argc, const char** argv)
{
// std::cout << " Caught (" << Standard_Failure::Caught() << ")... KO" << std::endl;
di << " Caught (";
di << anException.GetMessageString();
di << anException.what();
di << ")... KO\n";
Succes = false;
}
@@ -2333,7 +2333,7 @@ static int OCC6143(Draw_Interpretor& di, int argc, const char** argv)
{
// std::cout << " Caught (" << Standard_Failure::Caught() << ")... KO" << std::endl;
di << " Caught (";
di << anException.GetMessageString();
di << anException.what();
di << ")... KO\n";
Succes = false;
}
@@ -2427,14 +2427,14 @@ static Standard_NOINLINE int OCC30762(Draw_Interpretor& theDI, int theNbArgs, co
#endif
{
theDI << " Caught (";
theDI << aSegException.GetMessageString();
theDI << aSegException.what();
theDI << aSegException.GetStackString();
theDI << ")... OK\n";
}
catch (Standard_Failure const& anException)
{
theDI << " Caught (";
theDI << anException.GetMessageString();
theDI << anException.what();
theDI << anException.GetStackString();
theDI << ")... KO\n";
}
@@ -2504,7 +2504,7 @@ static int OCC7141(Draw_Interpretor& di, int argc, const char** argv)
{
di << "Failed :\n\n";
// std::cout << Standard_Failure::Caught() << std::endl;
di << anException.GetMessageString();
di << anException.what();
}
di << argv[0] << " : Finish\n";
@@ -4752,7 +4752,7 @@ int CR23403(Draw_Interpretor& di, int argc, const char** argv)
}
catch (Standard_Failure const& anException)
{
di << "Exception : " << anException.GetMessageString() << "\n";
di << "Exception : " << anException.what() << "\n";
}
return 0;
@@ -1049,7 +1049,7 @@ static int checkshape(Draw_Interpretor& theCommands, int narg, const char** a)
catch (Standard_Failure const& anException)
{
theCommands << "checkshape exception : ";
theCommands << anException.GetMessageString();
theCommands << anException.what();
theCommands << "\n";
return 1;
}
@@ -61,7 +61,7 @@ Standard_EXPORT const char* MeshTest_DrawLinks(const char* theNameStr, void* the
}
catch (Standard_Failure const& anException)
{
return anException.GetMessageString();
return anException.what();
}
}
@@ -108,6 +108,6 @@ Standard_EXPORT const char* MeshTest_DrawTriangles(const char* theNameStr, void*
}
catch (Standard_Failure const& anException)
{
return anException.GetMessageString();
return anException.what();
}
}
+1 -1
View File
@@ -737,7 +737,7 @@ static int CheckProps(Draw_Interpretor& di, int argc, const char** argv)
#ifdef OCCT_DEBUG
// fflush ( stdout );
di << ": ";
di << anException.GetMessageString();
di << anException.what();
di << " ** Skip\n";
#endif
(void)anException;
@@ -301,7 +301,7 @@ static int igesbrep(Draw_Interpretor& theDI, int theNbArgs, const char** theArgV
catch (Standard_Failure const& anException)
{
theDI << "** Exception : ";
theDI << anException.GetMessageString();
theDI << anException.what();
theDI << " ** Skip\n";
theDI << "Saving shape in variable Draw : " << fname << "\n";
WriteShape(shape, 1);
@@ -333,7 +333,7 @@ static int igesbrep(Draw_Interpretor& theDI, int theNbArgs, const char** theArgV
catch (Standard_Failure const& anException)
{
theDI << "** Exception : ";
theDI << anException.GetMessageString();
theDI << anException.what();
theDI << " ** Skip\n";
}
}
@@ -408,7 +408,7 @@ static int igesbrep(Draw_Interpretor& theDI, int theNbArgs, const char** theArgV
catch (Standard_Failure const& anException)
{
theDI << "** Exception : ";
theDI << anException.GetMessageString();
theDI << anException.what();
theDI << " ** Skip\n";
theDI << "Saving shape in variable Draw : " << fname << "\n";
WriteShape(shape, 1);
@@ -17,14 +17,10 @@
#ifndef _gp_VectorWithNullMagnitude_HeaderFile
#define _gp_VectorWithNullMagnitude_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_DefineException.hxx>
#include <Standard_SStream.hxx>
#include <Standard_DomainError.hxx>
class gp_VectorWithNullMagnitude;
DEFINE_STANDARD_HANDLE(gp_VectorWithNullMagnitude, Standard_DomainError)
#if !defined No_Exception && !defined No_gp_VectorWithNullMagnitude
#define gp_VectorWithNullMagnitude_Raise_if(CONDITION, MESSAGE) \
if (CONDITION) \
@@ -17,7 +17,6 @@
#ifndef _math_NotSquare_HeaderFile
#define _math_NotSquare_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_DefineException.hxx>
#include <Standard_SStream.hxx>
#include <Standard_DimensionError.hxx>
@@ -17,7 +17,6 @@
#ifndef _math_SingularMatrix_HeaderFile
#define _math_SingularMatrix_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_DefineException.hxx>
#include <Standard_SStream.hxx>
#include <Standard_Failure.hxx>
@@ -20,6 +20,8 @@
#include <Standard_TypeMismatch.hxx>
#include <Standard_Macro.hxx>
#include <cstring>
//! Defines an array of values of configurable size.
//! For instance, this class allows defining an array of 32-bit or 64-bit integer values with
//! bitness determined in runtime. The element size in bytes (stride) should be specified at
@@ -18,6 +18,7 @@
#include <Standard.hxx>
#include <algorithm>
#include <cstring>
//=================================================================================================
@@ -15,7 +15,6 @@
#ifndef _OSD_Exception_HeaderFile
#define _OSD_Exception_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_DefineException.hxx>
#include <Standard_SStream.hxx>
#include <Standard_Failure.hxx>
@@ -15,7 +15,6 @@
#ifndef _OSD_Exception_ACCESS_VIOLATION_HeaderFile
#define _OSD_Exception_ACCESS_VIOLATION_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_DefineException.hxx>
#include <Standard_SStream.hxx>
#include <OSD_Exception.hxx>
@@ -15,7 +15,6 @@
#ifndef _OSD_Exception_ARRAY_BOUNDS_EXCEEDED_HeaderFile
#define _OSD_Exception_ARRAY_BOUNDS_EXCEEDED_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_DefineException.hxx>
#include <Standard_SStream.hxx>
#include <OSD_Exception.hxx>
@@ -15,7 +15,6 @@
#ifndef _OSD_Exception_CTRL_BREAK_HeaderFile
#define _OSD_Exception_CTRL_BREAK_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_SStream.hxx>
#include <OSD_Exception.hxx>
@@ -15,7 +15,6 @@
#ifndef _OSD_Exception_ILLEGAL_INSTRUCTION_HeaderFile
#define _OSD_Exception_ILLEGAL_INSTRUCTION_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_DefineException.hxx>
#include <Standard_SStream.hxx>
#include <OSD_Exception.hxx>
@@ -15,7 +15,6 @@
#ifndef _OSD_Exception_INT_OVERFLOW_HeaderFile
#define _OSD_Exception_INT_OVERFLOW_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_DefineException.hxx>
#include <Standard_SStream.hxx>
#include <OSD_Exception.hxx>
@@ -15,7 +15,6 @@
#ifndef _OSD_Exception_INVALID_DISPOSITION_HeaderFile
#define _OSD_Exception_INVALID_DISPOSITION_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_DefineException.hxx>
#include <Standard_SStream.hxx>
#include <OSD_Exception.hxx>
@@ -15,7 +15,6 @@
#ifndef _OSD_Exception_IN_PAGE_ERROR_HeaderFile
#define _OSD_Exception_IN_PAGE_ERROR_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_DefineException.hxx>
#include <Standard_SStream.hxx>
#include <OSD_Exception.hxx>
@@ -15,7 +15,6 @@
#ifndef _OSD_Exception_NONCONTINUABLE_EXCEPTION_HeaderFile
#define _OSD_Exception_NONCONTINUABLE_EXCEPTION_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_DefineException.hxx>
#include <Standard_SStream.hxx>
#include <OSD_Exception.hxx>
@@ -15,7 +15,6 @@
#ifndef _OSD_Exception_PRIV_INSTRUCTION_HeaderFile
#define _OSD_Exception_PRIV_INSTRUCTION_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_DefineException.hxx>
#include <Standard_SStream.hxx>
#include <OSD_Exception.hxx>
@@ -15,7 +15,6 @@
#ifndef _OSD_Exception_STACK_OVERFLOW_HeaderFile
#define _OSD_Exception_STACK_OVERFLOW_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_DefineException.hxx>
#include <Standard_SStream.hxx>
#include <OSD_Exception.hxx>
@@ -15,7 +15,6 @@
#ifndef _OSD_Exception_STATUS_NO_MEMORY_HeaderFile
#define _OSD_Exception_STATUS_NO_MEMORY_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_DefineException.hxx>
#include <Standard_SStream.hxx>
#include <OSD_Exception.hxx>
@@ -15,7 +15,6 @@
#ifndef _OSD_OSDError_HeaderFile
#define _OSD_OSDError_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_DefineException.hxx>
#include <Standard_SStream.hxx>
#include <Standard_Failure.hxx>
@@ -15,7 +15,6 @@
#ifndef _OSD_SIGBUS_HeaderFile
#define _OSD_SIGBUS_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_SStream.hxx>
#include <OSD_Signal.hxx>
@@ -15,7 +15,6 @@
#ifndef _OSD_SIGHUP_HeaderFile
#define _OSD_SIGHUP_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_SStream.hxx>
#include <OSD_Signal.hxx>
@@ -15,7 +15,6 @@
#ifndef _OSD_SIGILL_HeaderFile
#define _OSD_SIGILL_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_SStream.hxx>
#include <OSD_Signal.hxx>
@@ -15,7 +15,6 @@
#ifndef _OSD_SIGINT_HeaderFile
#define _OSD_SIGINT_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_SStream.hxx>
#include <OSD_Signal.hxx>
@@ -15,7 +15,6 @@
#ifndef _OSD_SIGKILL_HeaderFile
#define _OSD_SIGKILL_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_SStream.hxx>
#include <OSD_Signal.hxx>
@@ -15,7 +15,6 @@
#ifndef _OSD_SIGQUIT_HeaderFile
#define _OSD_SIGQUIT_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_SStream.hxx>
#include <OSD_Signal.hxx>
@@ -15,7 +15,6 @@
#ifndef _OSD_SIGSEGV_HeaderFile
#define _OSD_SIGSEGV_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_DefineException.hxx>
#include <Standard_SStream.hxx>
#include <OSD_Signal.hxx>
@@ -15,7 +15,6 @@
#ifndef _OSD_SIGSYS_HeaderFile
#define _OSD_SIGSYS_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_SStream.hxx>
#include <OSD_Signal.hxx>
@@ -15,7 +15,6 @@
#ifndef _OSD_Signal_HeaderFile
#define _OSD_Signal_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_DefineException.hxx>
#include <Standard_SStream.hxx>
#include <Standard_Failure.hxx>
@@ -217,7 +217,7 @@ void OSD_ThreadPool::Launcher::wait()
aThreadIter.Next())
{
aThreadIter.ChangeValue()->WaitIdle();
if (!aThreadIter.Value()->myFailure.IsNull())
if (aThreadIter.Value()->myFailure)
{
++aNbFailures;
}
@@ -232,18 +232,19 @@ void OSD_ThreadPool::Launcher::wait()
aThreadIter.More() && aThreadIter.Value() != nullptr;
aThreadIter.Next())
{
if (!aThreadIter.Value()->myFailure.IsNull())
if (aThreadIter.Value()->myFailure)
{
if (aNbFailures == 1)
{
aThreadIter.Value()->myFailure->Reraise();
// Re-throw the single exception directly
throw *aThreadIter.Value()->myFailure;
}
if (!aFailures.IsEmpty())
{
aFailures += "\n";
}
aFailures += aThreadIter.Value()->myFailure->GetMessageString();
aFailures += aThreadIter.Value()->myFailure->what();
}
}
@@ -253,9 +254,9 @@ void OSD_ThreadPool::Launcher::wait()
//=================================================================================================
void OSD_ThreadPool::performJob(occ::handle<Standard_Failure>& theFailure,
OSD_ThreadPool::JobInterface* theJob,
int theThreadIndex)
void OSD_ThreadPool::performJob(std::optional<Standard_ProgramError>& theFailure,
OSD_ThreadPool::JobInterface* theJob,
int theThreadIndex)
{
try
{
@@ -265,18 +266,18 @@ void OSD_ThreadPool::performJob(occ::handle<Standard_Failure>& theFailure,
catch (Standard_Failure const& aFailure)
{
TCollection_AsciiString aMsg =
TCollection_AsciiString(aFailure.DynamicType()->Name()) + ": " + aFailure.GetMessageString();
theFailure = new Standard_ProgramError(aMsg.ToCString(), aFailure.GetStackString());
TCollection_AsciiString(aFailure.ExceptionType()) + ": " + aFailure.what();
theFailure.emplace(aMsg.ToCString(), aFailure.GetStackString());
}
catch (std::exception& anStdException)
{
TCollection_AsciiString aMsg =
TCollection_AsciiString(typeid(anStdException).name()) + ": " + anStdException.what();
theFailure = new Standard_ProgramError(aMsg.ToCString(), nullptr);
theFailure.emplace(aMsg.ToCString(), nullptr);
}
catch (...)
{
theFailure = new Standard_ProgramError("Error: Unknown exception", nullptr);
theFailure.emplace("Error: Unknown exception", nullptr);
}
}
@@ -294,7 +295,7 @@ void OSD_ThreadPool::EnumeratedThread::performThread()
return;
}
myFailure.Nullify();
myFailure.reset();
if (myJob != nullptr)
{
OSD::SetThreadLocalSignal(OSD::SignalMode(), myToCatchFpe);
@@ -19,7 +19,10 @@
#include <OSD_Thread.hxx>
#include <Standard_Condition.hxx>
#include <Standard_ProgramError.hxx>
#include <atomic>
#include <optional>
//! Class defining a thread pool for executing algorithms in multi-threaded mode.
//! Thread pool allocates requested amount of threads and keep them alive
@@ -183,16 +186,16 @@ protected:
static void* runThread(void* theTask);
private:
OSD_ThreadPool* myPool;
JobInterface* myJob;
occ::handle<Standard_Failure> myFailure;
Standard_Condition myWakeEvent;
Standard_Condition myIdleEvent;
int myThreadIndex;
std::atomic<int> myUsageCounter;
bool myIsStarted;
bool myToCatchFpe;
bool myIsSelfThread;
OSD_ThreadPool* myPool;
JobInterface* myJob;
std::optional<Standard_ProgramError> myFailure;
Standard_Condition myWakeEvent;
Standard_Condition myIdleEvent;
int myThreadIndex;
std::atomic<int> myUsageCounter;
bool myIsStarted;
bool myToCatchFpe;
bool myIsSelfThread;
};
public:
@@ -336,9 +339,9 @@ protected:
void release();
//! Perform the job and catch exceptions.
static void performJob(occ::handle<Standard_Failure>& theFailure,
OSD_ThreadPool::JobInterface* theJob,
int theThreadIndex);
static void performJob(std::optional<Standard_ProgramError>& theFailure,
OSD_ThreadPool::JobInterface* theJob,
int theThreadIndex);
private:
//! This method should not be called (prohibited).
@@ -12,6 +12,7 @@
// commercial license or contractual agreement.
#include <OSD.hxx>
#include <Standard_CString.hxx>
#include <OSD_Exception_CTRL_BREAK.hxx>
#include <Standard_DivideByZero.hxx>
#include <Standard_Overflow.hxx>
@@ -106,7 +107,7 @@ static LONG _osd_debug(void);
#define _OSD_FPX (_EM_INVALID | _EM_DENORMAL | _EM_ZERODIVIDE | _EM_OVERFLOW)
#ifdef OCC_CONVERT_SIGNALS
#define THROW_OR_JUMP(Type, Message, Stack) Type::NewInstance(Message, Stack)->Jump()
#define THROW_OR_JUMP(Type, Message, Stack) Standard_ErrorHandler::Abort(Type(Message, Stack))
#else
#define THROW_OR_JUMP(Type, Message, Stack) throw Type(Message, Stack)
#endif
@@ -818,41 +819,41 @@ static void Handler(const int theSignal)
switch (theSignal)
{
case SIGHUP:
OSD_SIGHUP::NewInstance("SIGHUP 'hangup' detected.")->Jump();
Standard_ErrorHandler::Abort(OSD_SIGHUP("SIGHUP 'hangup' detected."));
exit(SIGHUP);
break;
case SIGINT:
// For safe handling of Control-C as stop event, arm a variable but do not
// generate longjump (we are out of context anyway)
fCtrlBrk = true;
// OSD_SIGINT::NewInstance("SIGINT 'interrupt' detected.")->Jump();
// Standard_ErrorHandler::Abort(OSD_SIGINT("SIGINT 'interrupt' detected."));
// exit(SIGINT);
break;
case SIGQUIT:
OSD_SIGQUIT::NewInstance("SIGQUIT 'quit' detected.")->Jump();
Standard_ErrorHandler::Abort(OSD_SIGQUIT("SIGQUIT 'quit' detected."));
exit(SIGQUIT);
break;
case SIGILL:
OSD_SIGILL::NewInstance("SIGILL 'illegal instruction' detected.")->Jump();
Standard_ErrorHandler::Abort(OSD_SIGILL("SIGILL 'illegal instruction' detected."));
exit(SIGILL);
break;
case SIGKILL:
OSD_SIGKILL::NewInstance("SIGKILL 'kill' detected.")->Jump();
Standard_ErrorHandler::Abort(OSD_SIGKILL("SIGKILL 'kill' detected."));
exit(SIGKILL);
break;
case SIGBUS:
sigaddset(&set, SIGBUS);
sigprocmask(SIG_UNBLOCK, &set, nullptr);
OSD_SIGBUS::NewInstance("SIGBUS 'bus error' detected.")->Jump();
Standard_ErrorHandler::Abort(OSD_SIGBUS("SIGBUS 'bus error' detected."));
exit(SIGBUS);
break;
case SIGSEGV:
OSD_SIGSEGV::NewInstance("SIGSEGV 'segmentation violation' detected.")->Jump();
Standard_ErrorHandler::Abort(OSD_SIGSEGV("SIGSEGV 'segmentation violation' detected."));
exit(SIGSEGV);
break;
#ifdef SIGSYS
case SIGSYS:
OSD_SIGSYS::NewInstance("SIGSYS 'bad argument to system call' detected.")->Jump();
Standard_ErrorHandler::Abort(OSD_SIGSYS("SIGSYS 'bad argument to system call' detected."));
exit(SIGSYS);
break;
#endif
@@ -863,7 +864,7 @@ static void Handler(const int theSignal)
OSD::SetFloatingSignal(true);
#endif
#if (!defined(__sun)) && (!defined(SOLARIS))
Standard_NumericError::NewInstance("SIGFPE Arithmetic exception detected")->Jump();
Standard_ErrorHandler::Abort(Standard_NumericError("SIGFPE Arithmetic exception detected"));
break;
#else
// Reste SOLARIS
@@ -872,34 +873,34 @@ static void Handler(const int theSignal)
switch (aSigInfo->si_code)
{
case FPE_FLTDIV_TRAP:
Standard_DivideByZero::NewInstance("Floating Divide By Zero")->Jump();
Standard_ErrorHandler::Abort(Standard_DivideByZero("Floating Divide By Zero"));
break;
case FPE_INTDIV_TRAP:
Standard_DivideByZero::NewInstance("Integer Divide By Zero")->Jump();
Standard_ErrorHandler::Abort(Standard_DivideByZero("Integer Divide By Zero"));
break;
case FPE_FLTOVF_TRAP:
Standard_Overflow::NewInstance("Floating Overflow")->Jump();
Standard_ErrorHandler::Abort(Standard_Overflow("Floating Overflow"));
break;
case FPE_INTOVF_TRAP:
Standard_Overflow::NewInstance("Integer Overflow")->Jump();
Standard_ErrorHandler::Abort(Standard_Overflow("Integer Overflow"));
break;
case FPE_FLTUND_TRAP:
Standard_NumericError::NewInstance("Floating Underflow")->Jump();
Standard_ErrorHandler::Abort(Standard_NumericError("Floating Underflow"));
break;
case FPE_FLTRES_TRAP:
Standard_NumericError::NewInstance("Floating Point Inexact Result")->Jump();
Standard_ErrorHandler::Abort(Standard_NumericError("Floating Point Inexact Result"));
break;
case FPE_FLTINV_TRAP:
Standard_NumericError::NewInstance("Invalid Floating Point Operation")->Jump();
Standard_ErrorHandler::Abort(Standard_NumericError("Invalid Floating Point Operation"));
break;
default:
Standard_NumericError::NewInstance("Numeric Error")->Jump();
Standard_ErrorHandler::Abort(Standard_NumericError("Numeric Error"));
break;
}
}
else
{
Standard_NumericError::NewInstance("SIGFPE Arithmetic exception detected")->Jump();
Standard_ErrorHandler::Abort(Standard_NumericError("SIGFPE Arithmetic exception detected"));
}
#endif
break;
@@ -940,7 +941,7 @@ static void SegvHandler(const int theSignal, siginfo_t* theSigInfo, void* const
Standard::StackTrace(aStackBuffer, aStackBufLen, aStackLength);
}
OSD_SIGSEGV::NewInstance(aMsg, aStackBuffer)->Jump();
Standard_ErrorHandler::Abort(OSD_SIGSEGV(aMsg, aStackBuffer));
}
}
#ifdef OCCT_DEBUG
@@ -965,7 +966,7 @@ static void SegvHandler(const int theSignal, siginfo_t* theSigInfo, void* const
{
char aMsg[100];
Sprintf(aMsg, "SIGSEGV 'segmentation violation' detected. Address %lx", anOffset);
OSD_SIGSEGV::NewInstance(aMsg)->Jump();
Standard_ErrorHandler::Abort(OSD_SIGSEGV(aMsg));
}
}
#ifdef OCCT_DEBUG
@@ -17,7 +17,6 @@
#ifndef _Plugin_Failure_HeaderFile
#define _Plugin_Failure_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_DefineException.hxx>
#include <Standard_SStream.hxx>
#include <Standard_Failure.hxx>
@@ -17,7 +17,6 @@
#ifndef _Quantity_DateDefinitionError_HeaderFile
#define _Quantity_DateDefinitionError_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_SStream.hxx>
#include <Standard_DomainError.hxx>
@@ -17,7 +17,6 @@
#ifndef _Quantity_PeriodDefinitionError_HeaderFile
#define _Quantity_PeriodDefinitionError_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_SStream.hxx>
#include <Standard_DomainError.hxx>
@@ -17,7 +17,6 @@
#ifndef _Resource_NoSuchResource_HeaderFile
#define _Resource_NoSuchResource_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_DefineException.hxx>
#include <Standard_SStream.hxx>
#include <Standard_NoSuchObject.hxx>
@@ -17,7 +17,6 @@
#ifndef _Standard_AbortiveTransaction_HeaderFile
#define _Standard_AbortiveTransaction_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_DefineException.hxx>
#include <Standard_SStream.hxx>
#include <Standard_Failure.hxx>
@@ -17,7 +17,6 @@
#ifndef _Standard_ConstructionError_HeaderFile
#define _Standard_ConstructionError_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_DefineException.hxx>
#include <Standard_SStream.hxx>
#include <Standard_DomainError.hxx>
@@ -14,59 +14,41 @@
#ifndef _Standard_DefineException_HeaderFile
#define _Standard_DefineException_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_SStream.hxx>
//! Defines an exception class \a C1 that inherits an exception class \a C2.
/*! \a C2 must be Standard_Failure or its ancestor.
The macro defines empty constructor, copy constructor and static methods Raise() and
NewInstance(). Since Standard_Failure implements class manipulated by handle,
DEFINE_STANDARD_RTTI macro is also added to enable RTTI.
When using DEFINE_STANDARD_EXCEPTION in your code make sure you also insert a macro
DEFINE_STANDARD_HANDLE(C1,C2) before it.
*/
#include <memory>
//! @brief Defines an exception class inheriting from Standard_Failure.
//!
//! This macro creates a complete exception class with:
//! - Constructors that forward to base class
//! - ExceptionType() override returning the class name
//!
//! Usage:
//! @code
//! DEFINE_STANDARD_EXCEPTION(Standard_OutOfRange, Standard_RangeError)
//! @endcode
//!
//! @param C1 Name of the exception class to define
//! @param C2 Name of the parent exception class (must be Standard_Failure or derived)
#define DEFINE_STANDARD_EXCEPTION(C1, C2) \
\
class C1 : public C2 \
{ \
void Throw() const override \
{ \
throw *this; \
} \
\
public: \
C1() {} \
C1(const char* theMessage) \
C1(const char* theMessage = "") \
: C2(theMessage) \
{ \
} \
\
C1(const char* theMessage, const char* theStackTrace) \
: C2(theMessage, theStackTrace) \
{ \
} \
static void Raise(const char* theMessage = "") \
\
const char* ExceptionType() const noexcept override \
{ \
occ::handle<C1> _E = new C1; \
_E->Reraise(theMessage); \
return #C1; \
} \
static void Raise(Standard_SStream& theMessage) \
{ \
occ::handle<C1> _E = new C1; \
_E->Reraise(theMessage); \
} \
static occ::handle<C1> NewInstance(const char* theMessage = "") \
{ \
return new C1(theMessage); \
} \
static occ::handle<C1> NewInstance(const char* theMessage, const char* theStackTrace) \
{ \
return new C1(theMessage, theStackTrace); \
} \
DEFINE_STANDARD_RTTI_INLINE(C1, C2) \
};
//! Obsolete macro, kept for compatibility with old code
#define IMPLEMENT_STANDARD_EXCEPTION(C1)
#endif
@@ -17,7 +17,6 @@
#ifndef _Standard_DimensionError_HeaderFile
#define _Standard_DimensionError_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_DefineException.hxx>
#include <Standard_SStream.hxx>
#include <Standard_DomainError.hxx>
@@ -17,7 +17,6 @@
#ifndef _Standard_DimensionMismatch_HeaderFile
#define _Standard_DimensionMismatch_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_DefineException.hxx>
#include <Standard_SStream.hxx>
#include <Standard_DimensionError.hxx>
@@ -17,7 +17,6 @@
#ifndef _Standard_DivideByZero_HeaderFile
#define _Standard_DivideByZero_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_DefineException.hxx>
#include <Standard_SStream.hxx>
#include <Standard_NumericError.hxx>
@@ -17,7 +17,6 @@
#ifndef _Standard_DomainError_HeaderFile
#define _Standard_DomainError_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_DefineException.hxx>
#include <Standard_SStream.hxx>
#include <Standard_Failure.hxx>
@@ -14,8 +14,6 @@
#include <Standard_ErrorHandler.hxx>
#include <Standard_Failure.hxx>
// During [sig]setjmp()/[sig]longjmp() K_SETJMP is non zero (try)
// So if there is an abort request and if K_SETJMP is non zero, the abort
// request will be ignored. If the abort request do a raise during a setjmp
@@ -77,34 +75,25 @@ bool Standard_ErrorHandler::IsInTryBlock()
//=================================================================================================
void Standard_ErrorHandler::Abort(const occ::handle<Standard_Failure>& theError)
{
Standard_ErrorHandler* anActive = FindHandler();
if (anActive == nullptr)
{
std::cerr << "*** Abort *** an exception was raised, but no catch was found." << std::endl;
if (!theError.IsNull())
std::cerr << "\t... The exception is:" << theError->GetMessageString() << std::endl;
exit(1);
}
anActive->myCaughtError = theError;
longjmp(anActive->myLabel, true);
}
//=================================================================================================
void Standard_ErrorHandler::Raise()
{
if (myCaughtError.IsNull())
if (std::holds_alternative<std::monostate>(myCaughtError))
{
std::cerr << "*** Abort *** an exception handler was called, but not exception object is set."
std::cerr << "*** Abort *** an exception handler was called, but no exception object is set."
<< std::endl;
exit(1);
}
myCaughtError->Reraise();
// Visit the variant and throw the appropriate exception type
std::visit(
[](auto&& theException) {
using T = std::decay_t<decltype(theException)>;
if constexpr (!std::is_same_v<T, std::monostate>)
{
throw theException;
}
},
myCaughtError);
}
//=================================================================================================
@@ -18,10 +18,35 @@
#define _Standard_ErrorHandler_HeaderFile
#include <Standard.hxx>
#include <Standard_Handle.hxx>
#include <Standard_Type.hxx>
#include <setjmp.h>
#include <variant>
#include <iostream>
// Signal exception types for variant storage
#include <OSD_SIGBUS.hxx>
#include <OSD_SIGHUP.hxx>
#include <OSD_SIGILL.hxx>
#include <OSD_SIGINT.hxx>
#include <OSD_SIGKILL.hxx>
#include <OSD_SIGQUIT.hxx>
#include <OSD_SIGSEGV.hxx>
#include <OSD_SIGSYS.hxx>
#include <OSD_Exception_ACCESS_VIOLATION.hxx>
#include <OSD_Exception_ARRAY_BOUNDS_EXCEEDED.hxx>
#include <OSD_Exception_ILLEGAL_INSTRUCTION.hxx>
#include <OSD_Exception_IN_PAGE_ERROR.hxx>
#include <OSD_Exception_INT_OVERFLOW.hxx>
#include <OSD_Exception_INVALID_DISPOSITION.hxx>
#include <OSD_Exception_NONCONTINUABLE_EXCEPTION.hxx>
#include <OSD_Exception_PRIV_INSTRUCTION.hxx>
#include <OSD_Exception_STACK_OVERFLOW.hxx>
#include <OSD_Exception_STATUS_NO_MEMORY.hxx>
#include <Standard_DivideByZero.hxx>
#include <Standard_NumericError.hxx>
#include <Standard_Overflow.hxx>
#include <Standard_ProgramError.hxx>
#include <Standard_Underflow.hxx>
//! @file
//! Support of handling of C signals as C++-style exceptions, and implementation
@@ -65,8 +90,6 @@
#endif
class Standard_Failure;
//! Class implementing mechanics of conversion of signals to exceptions.
//!
//! Each instance of it stores data for jump placement,
@@ -76,6 +99,34 @@ class Standard_Failure;
//! to find appropriate handler when signal is raised.
class Standard_ErrorHandler
{
public:
//! Variant type holding all possible signal exceptions.
//! Used to store exception across longjmp without heap allocation.
using SignalException = std::variant<std::monostate, // Empty state (no exception)
OSD_SIGBUS,
OSD_SIGHUP,
OSD_SIGILL,
OSD_SIGINT,
OSD_SIGKILL,
OSD_SIGQUIT,
OSD_SIGSEGV,
OSD_SIGSYS,
OSD_Exception_ACCESS_VIOLATION,
OSD_Exception_ARRAY_BOUNDS_EXCEEDED,
OSD_Exception_ILLEGAL_INSTRUCTION,
OSD_Exception_IN_PAGE_ERROR,
OSD_Exception_INT_OVERFLOW,
OSD_Exception_INVALID_DISPOSITION,
OSD_Exception_NONCONTINUABLE_EXCEPTION,
OSD_Exception_PRIV_INSTRUCTION,
OSD_Exception_STACK_OVERFLOW,
OSD_Exception_STATUS_NO_MEMORY,
Standard_DivideByZero,
Standard_NumericError,
Standard_Overflow,
Standard_ProgramError,
Standard_Underflow>;
public:
DEFINE_STANDARD_ALLOC
@@ -96,23 +147,25 @@ public:
//! Returns label for jump
jmp_buf& Label() { return myLabel; }
//! Returns the current Error.
const occ::handle<Standard_Failure>& Error() const { return myCaughtError; }
//! Returns the current Error variant.
const SignalException& Error() const { return myCaughtError; }
//! Test if the code is currently running in a try block
Standard_EXPORT static bool IsInTryBlock();
//! Abort with specific exception type.
//! Finds nearest error handler, stores exception, and performs longjmp.
//! @tparam T Exception type (must be one of Standard_SignalException variant types)
//! @param theError Exception to store and throw after longjmp
template <typename T>
static void Abort(const T& theError);
private:
//! Removes handler from the list.
void Unlink();
//! Finds nearest error handler in the stack and sets its exception object to @p theError
//! and long jump which then throw normal C++ exception.
//! If handler not found, prints error and exit program with error code @c 1.
static void Abort(const occ::handle<Standard_Failure>& theError);
//! Returns the current handler (closest in the stack in the current execution thread)
static Standard_ErrorHandler* FindHandler();
Standard_EXPORT static Standard_ErrorHandler* FindHandler();
public:
//! Defines a base class for callback objects that can be registered
@@ -178,14 +231,31 @@ public:
};
private:
Standard_ErrorHandler* myPrevious = nullptr;
occ::handle<Standard_Failure> myCaughtError;
jmp_buf myLabel = {};
Callback* myCallbackPtr = nullptr;
friend class Standard_Failure;
SignalException myCaughtError;
Standard_ErrorHandler* myPrevious = nullptr;
Callback* myCallbackPtr = nullptr;
jmp_buf myLabel = {};
};
//! Template implementation of Abort - stores exception and performs longjmp.
template <typename T>
void Standard_ErrorHandler::Abort(const T& theError)
{
#ifndef OCC_CONVERT_SIGNALS
throw theError;
#else
Standard_ErrorHandler* anActive = FindHandler();
if (anActive == nullptr)
{
std::cerr << "*** Abort *** an exception was raised, but no catch was found." << std::endl;
std::cerr << "\t... The exception is: " << theError.what() << std::endl;
exit(1);
}
anActive->myCaughtError = theError;
longjmp(anActive->myLabel, true);
#endif
}
// If OCC_CONVERT_SIGNALS is not defined,
// provide empty inline implementation
#if !defined(OCC_CONVERT_SIGNALS)
@@ -15,16 +15,10 @@
#include <Standard_Failure.hxx>
#include <Standard_ErrorHandler.hxx>
#include <Standard_Macro.hxx>
#include <Standard_NoSuchObject.hxx>
#include <Standard_PCharacter.hxx>
#include <Standard_Type.hxx>
#include <Standard_TypeMismatch.hxx>
#include <algorithm>
#include <cstring>
IMPLEMENT_STANDARD_RTTIEXT(Standard_Failure, Standard_Transient)
namespace
{
//! Global parameter defining default length of stack trace.
@@ -33,18 +27,18 @@ static int Standard_Failure_DefaultStackTraceLength = 0;
//=================================================================================================
Standard_Failure::StringRef* Standard_Failure::StringRef::allocate_message(const char* theString)
Standard_Failure::StringRef* Standard_Failure::StringRef::Allocate(const char* theString)
{
if (theString == nullptr || *theString == '\0')
if (theString == nullptr || theString[0] == '\0')
{
return nullptr;
}
const size_t aLen = strlen(theString);
const size_t aLen = std::strlen(theString);
StringRef* aStrPtr = (StringRef*)Standard::AllocateOptimal(aLen + sizeof(int) + 1);
if (aStrPtr != nullptr)
{
strcpy((char*)&aStrPtr->Message[0], theString);
std::strcpy(&aStrPtr->Message[0], theString);
aStrPtr->Counter = 1;
}
return aStrPtr;
@@ -52,8 +46,7 @@ Standard_Failure::StringRef* Standard_Failure::StringRef::allocate_message(const
//=================================================================================================
Standard_Failure::StringRef* Standard_Failure::StringRef::copy_message(
Standard_Failure::StringRef* theString)
Standard_Failure::StringRef* Standard_Failure::StringRef::Copy(StringRef* theString)
{
if (theString == nullptr)
{
@@ -66,13 +59,34 @@ Standard_Failure::StringRef* Standard_Failure::StringRef::copy_message(
//=================================================================================================
void Standard_Failure::StringRef::deallocate_message(Standard_Failure::StringRef* theString)
void Standard_Failure::StringRef::Free(StringRef* theString)
{
if (theString != nullptr)
{
if (--theString->Counter == 0)
{
Standard::Free((void*)theString);
Standard::Free(theString);
}
}
}
//=================================================================================================
void Standard_Failure::captureStackTrace()
{
const int aStackLength = Standard_Failure_DefaultStackTraceLength;
if (aStackLength > 0)
{
// Limit stack allocation to 64KB to prevent stack overflow
const int aStackBufLen = std::clamp(aStackLength * 200, 2048, 65536);
char* aStackBuffer = (char*)alloca(aStackBufLen);
if (aStackBuffer != nullptr)
{
std::memset(aStackBuffer, 0, aStackBufLen);
if (Standard::StackTrace(aStackBuffer, aStackBufLen, aStackLength, nullptr, 1))
{
myStackTrace = StringRef::Allocate(aStackBuffer);
}
}
}
}
@@ -83,94 +97,71 @@ Standard_Failure::Standard_Failure()
: myMessage(nullptr),
myStackTrace(nullptr)
{
const int aStackLength = Standard_Failure_DefaultStackTraceLength;
if (aStackLength > 0)
{
int aStackBufLen = std::max(aStackLength * 200, 2048);
char* aStackBuffer = (char*)alloca(aStackBufLen);
if (aStackBuffer != nullptr)
{
memset(aStackBuffer, 0, aStackBufLen);
if (Standard::StackTrace(aStackBuffer, aStackBufLen, aStackLength, nullptr, 1))
{
myStackTrace = StringRef::allocate_message(aStackBuffer);
}
}
}
captureStackTrace();
}
//=================================================================================================
Standard_Failure::Standard_Failure(const char* theDesc)
Standard_Failure::Standard_Failure(const char* theMessage)
: myMessage(nullptr),
myStackTrace(nullptr)
{
myMessage = StringRef::allocate_message(theDesc);
const int aStackLength = Standard_Failure_DefaultStackTraceLength;
if (aStackLength > 0)
{
int aStackBufLen = std::max(aStackLength * 200, 2048);
char* aStackBuffer = (char*)alloca(aStackBufLen);
if (aStackBuffer != nullptr)
{
memset(aStackBuffer, 0, aStackBufLen);
Standard::StackTrace(aStackBuffer, aStackBufLen, aStackLength, nullptr, 1);
myStackTrace = StringRef::allocate_message(aStackBuffer);
}
}
myMessage = StringRef::Allocate(theMessage);
captureStackTrace();
}
//=================================================================================================
Standard_Failure::Standard_Failure(const char* theDesc, const char* theStackTrace)
Standard_Failure::Standard_Failure(const char* theMessage, const char* theStackTrace)
: myMessage(nullptr),
myStackTrace(nullptr)
{
myMessage = StringRef::allocate_message(theDesc);
myStackTrace = StringRef::allocate_message(theStackTrace);
myMessage = StringRef::Allocate(theMessage);
myStackTrace = StringRef::Allocate(theStackTrace);
}
//=================================================================================================
Standard_Failure::Standard_Failure(const Standard_Failure& theFailure)
: Standard_Transient(theFailure),
Standard_Failure::Standard_Failure(const Standard_Failure& theOther)
: std::exception(theOther),
myMessage(nullptr),
myStackTrace(nullptr)
{
myMessage = StringRef::copy_message(theFailure.myMessage);
myStackTrace = StringRef::copy_message(theFailure.myStackTrace);
myMessage = StringRef::Copy(theOther.myMessage);
myStackTrace = StringRef::Copy(theOther.myStackTrace);
}
//=================================================================================================
Standard_Failure& Standard_Failure::operator=(const Standard_Failure& theOther)
{
if (this != &theOther)
{
StringRef::Free(myMessage);
StringRef::Free(myStackTrace);
myMessage = StringRef::Copy(theOther.myMessage);
myStackTrace = StringRef::Copy(theOther.myStackTrace);
}
return *this;
}
//=================================================================================================
Standard_Failure::~Standard_Failure()
{
StringRef::deallocate_message(myMessage);
StringRef::deallocate_message(myStackTrace);
StringRef::Free(myMessage);
StringRef::Free(myStackTrace);
}
//=================================================================================================
const char* Standard_Failure::GetMessageString() const
const char* Standard_Failure::what() const noexcept
{
return myMessage != nullptr ? myMessage->GetMessage() : "";
}
//=================================================================================================
void Standard_Failure::SetMessageString(const char* theDesc)
{
if (theDesc == GetMessageString())
{
return;
}
StringRef::deallocate_message(myMessage);
myMessage = StringRef::allocate_message(theDesc);
}
//=================================================================================================
const char* Standard_Failure::GetStackString() const
{
return myStackTrace != nullptr ? myStackTrace->GetMessage() : "";
@@ -178,109 +169,24 @@ const char* Standard_Failure::GetStackString() const
//=================================================================================================
void Standard_Failure::SetStackString(const char* theStack)
{
if (theStack == GetStackString())
{
return;
}
StringRef::deallocate_message(myStackTrace);
myStackTrace = StringRef::allocate_message(theStack);
}
//=================================================================================================
void Standard_Failure::Raise(const char* theDesc)
{
occ::handle<Standard_Failure> aFailure = new Standard_Failure();
aFailure->Reraise(theDesc);
}
//=================================================================================================
void Standard_Failure::Raise(const Standard_SStream& theReason)
{
occ::handle<Standard_Failure> aFailure = new Standard_Failure();
aFailure->Reraise(theReason);
}
//=================================================================================================
void Standard_Failure::Reraise(const char* theDesc)
{
SetMessageString(theDesc);
Reraise();
}
//=================================================================================================
void Standard_Failure::Reraise(const Standard_SStream& theReason)
{
SetMessageString(theReason.str().c_str());
Reraise();
}
//=================================================================================================
void Standard_Failure::Reraise()
{
Throw();
}
//=================================================================================================
void Standard_Failure::Jump()
{
#if defined(OCC_CONVERT_SIGNALS)
Standard_ErrorHandler::Abort(this);
#else
Throw();
#endif
}
//=================================================================================================
void Standard_Failure::Throw() const
{
throw *this;
}
//=================================================================================================
void Standard_Failure::Print(Standard_OStream& theStream) const
{
if (myMessage != nullptr)
{
theStream << DynamicType() << ": " << GetMessageString();
theStream << ExceptionType() << ": " << myMessage->GetMessage();
}
else
{
theStream << DynamicType();
theStream << ExceptionType();
}
if (myStackTrace != nullptr)
{
theStream << GetStackString();
theStream << myStackTrace->GetMessage();
}
}
//=================================================================================================
occ::handle<Standard_Failure> Standard_Failure::NewInstance(const char* theString)
{
return new Standard_Failure(theString);
}
//=================================================================================================
occ::handle<Standard_Failure> Standard_Failure::NewInstance(const char* theMessage,
const char* theStackTrace)
{
return new Standard_Failure(theMessage, theStackTrace);
}
//=================================================================================================
int Standard_Failure::DefaultStackTraceLength()
{
return Standard_Failure_DefaultStackTraceLength;
@@ -17,82 +17,62 @@
#ifndef _Standard_Failure_HeaderFile
#define _Standard_Failure_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_CString.hxx>
#include <Standard_Transient.hxx>
#include <Standard.hxx>
#include <Standard_OStream.hxx>
#include <Standard_SStream.hxx>
#include <exception>
//! Forms the root of the entire exception hierarchy.
class Standard_Failure : public Standard_Transient
//! Inherits from std::exception and implements what() interface.
class Standard_Failure : public std::exception
{
public:
DEFINE_STANDARD_ALLOC
//! Creates a status object of type "Failure".
Standard_EXPORT Standard_Failure();
//! Copy constructor
Standard_EXPORT Standard_Failure(const Standard_Failure& f);
Standard_EXPORT Standard_Failure(const Standard_Failure& theOther);
//! Creates a status object of type "Failure".
//! @param[in] theDesc exception description
Standard_EXPORT Standard_Failure(const char* theDesc);
//! Creates a status object of type "Failure" with message.
//! @param[in] theMessage exception description
Standard_EXPORT Standard_Failure(const char* theMessage);
//! Creates a status object of type "Failure" with stack trace.
//! @param[in] theDesc exception description
//! @param[in] theStackTrace associated stack trace
Standard_EXPORT Standard_Failure(const char* theDesc, const char* theStackTrace);
//! Creates a status object of type "Failure" with message and stack trace.
//! @param[in] theMessage exception description
//! @param[in] theStackTrace stack trace string
Standard_EXPORT Standard_Failure(const char* theMessage, const char* theStackTrace);
//! Assignment operator
Standard_EXPORT Standard_Failure& operator=(const Standard_Failure& f);
Standard_EXPORT Standard_Failure& operator=(const Standard_Failure& theOther);
//! Destructor
Standard_EXPORT ~Standard_Failure() override;
//! Prints on the stream @p theStream the exception name followed by the error message.
//!
//! Note: there is a short-cut @c operator<< (Standard_OStream&, occ::handle<Standard_Failure>&)
Standard_EXPORT void Print(Standard_OStream& theStream) const;
//! Returns error message (implements std::exception interface).
//! Returns empty string "" if no message was set.
Standard_EXPORT const char* what() const noexcept override;
//! Returns error message
Standard_EXPORT virtual const char* GetMessageString() const;
Standard_DEPRECATED("Use what() instead")
const char* GetMessageString() const noexcept { return what(); }
//! Sets error message
Standard_EXPORT virtual void SetMessageString(const char* theMessage);
//! Returns the exception type name.
//! Default implementation returns "Standard_Failure".
//! Derived classes override this to return their own type name.
virtual const char* ExceptionType() const noexcept { return "Standard_Failure"; }
//! Returns the stack trace string
Standard_EXPORT virtual const char* GetStackString() const;
//! Returns the stack trace string (empty string if not available).
Standard_EXPORT const char* GetStackString() const;
//! Sets the stack trace string
Standard_EXPORT virtual void SetStackString(const char* theStack);
Standard_EXPORT void Reraise();
Standard_EXPORT void Reraise(const char* aMessage);
//! Reraises a caught exception and changes its error message.
Standard_EXPORT void Reraise(const Standard_SStream& aReason);
//! Prints on the stream @p theStream the exception name followed by the error message.
//!
//! Note: there is a short-cut @c operator<< (Standard_OStream&, const Standard_Failure&)
Standard_EXPORT void Print(Standard_OStream& theStream) const;
public:
//! Raises an exception of type "Failure" and associates
//! an error message to it. The message can be printed
//! in an exception handler.
Standard_EXPORT static void Raise(const char* aMessage = "");
//! Raises an exception of type "Failure" and associates
//! an error message to it. The message can be constructed
//! at run-time.
Standard_EXPORT static void Raise(const Standard_SStream& aReason);
//! Used to construct an instance of the exception object as a handle.
//! Shall be used to protect against possible construction of exception object in C stack,
//! which is dangerous since some of methods require that object was allocated dynamically.
Standard_EXPORT static occ::handle<Standard_Failure> NewInstance(const char* theMessage);
//! Used to construct an instance of the exception object as a handle.
Standard_EXPORT static occ::handle<Standard_Failure> NewInstance(const char* theMessage,
const char* theStackTrace);
//! Returns the default length of stack trace to be captured by Standard_Failure constructor;
//! 0 by default meaning no stack trace.
Standard_EXPORT static int DefaultStackTraceLength();
@@ -100,65 +80,37 @@ public:
//! Sets default length of stack trace to be captured by Standard_Failure constructor.
Standard_EXPORT static void SetDefaultStackTraceLength(int theNbStackTraces);
public:
//! Used to throw CASCADE exception from C signal handler.
//! On platforms that do not allow throwing C++ exceptions
//! from this handler (e.g. Linux), uses longjump to get to
//! the current active signal handler, and only then is
//! converted to C++ exception.
Standard_EXPORT void Jump();
DEFINE_STANDARD_RTTIEXT(Standard_Failure, Standard_Transient)
protected:
//! Used only if standard C++ exceptions are used.
//! Throws exception of the same type as this by C++ throw,
//! and stores current object as last thrown exception,
//! to be accessible by method Caught()
Standard_EXPORT virtual void Throw() const;
private:
//! Reference-counted string,
//! Memory block is allocated with an extra 4-byte header (int representing number of references)
//! using low-level malloc() to avoid exceptions.
//! Reference-counted string using malloc/free for exception safety.
//! Memory block has a 4-byte header (int for reference count).
struct StringRef
{
int Counter;
char Message[1];
//! Return message string.
const char* GetMessage() const { return (const char*)&Message[0]; }
const char* GetMessage() const { return &Message[0]; }
//! Allocate reference-counted message string.
static StringRef* allocate_message(const char* theString);
static StringRef* Allocate(const char* theString);
//! Copy reference-counted message string.
static StringRef* copy_message(StringRef* theString);
//! Copy reference-counted message string (increments counter).
static StringRef* Copy(StringRef* theString);
//! Release reference-counted message string.
static void deallocate_message(StringRef* theString);
static void Free(StringRef* theString);
};
//! Captures stack trace if configured.
void captureStackTrace();
private:
StringRef* myMessage;
StringRef* myStackTrace;
StringRef* myMessage; //!< Exception message
StringRef* myStackTrace; //!< Stack trace (optional)
};
// =======================================================================
// function : operator<<
// purpose :
// =======================================================================
inline Standard_OStream& operator<<(Standard_OStream& theStream,
const occ::handle<Standard_Failure>& theFailure)
{
theFailure->Print(theStream);
return theStream;
}
//=================================================================================================
// =======================================================================
// function : operator<<
// purpose :
// =======================================================================
inline Standard_OStream& operator<<(Standard_OStream& theStream, const Standard_Failure& theFailure)
{
theFailure.Print(theStream);
@@ -17,7 +17,6 @@
#ifndef _Standard_ImmutableObject_HeaderFile
#define _Standard_ImmutableObject_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_DefineException.hxx>
#include <Standard_SStream.hxx>
#include <Standard_DomainError.hxx>
@@ -17,7 +17,6 @@
#ifndef _Standard_LicenseError_HeaderFile
#define _Standard_LicenseError_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_DefineException.hxx>
#include <Standard_SStream.hxx>
#include <Standard_Failure.hxx>
@@ -17,7 +17,6 @@
#ifndef _Standard_LicenseNotFound_HeaderFile
#define _Standard_LicenseNotFound_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_DefineException.hxx>
#include <Standard_SStream.hxx>
#include <Standard_LicenseError.hxx>
@@ -21,6 +21,7 @@
#include <Standard_OutOfMemory.hxx>
#include <Standard_Assert.hxx>
#include <cstring>
#include <cstdio>
#include <cerrno>
@@ -17,7 +17,6 @@
#ifndef _Standard_MultiplyDefined_HeaderFile
#define _Standard_MultiplyDefined_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_DefineException.hxx>
#include <Standard_SStream.hxx>
#include <Standard_DomainError.hxx>
@@ -17,7 +17,6 @@
#ifndef _Standard_NegativeValue_HeaderFile
#define _Standard_NegativeValue_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_DefineException.hxx>
#include <Standard_SStream.hxx>
#include <Standard_RangeError.hxx>
@@ -17,7 +17,6 @@
#ifndef _Standard_NoMoreObject_HeaderFile
#define _Standard_NoMoreObject_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_DefineException.hxx>
#include <Standard_SStream.hxx>
#include <Standard_DomainError.hxx>
@@ -17,7 +17,6 @@
#ifndef _Standard_NoSuchObject_HeaderFile
#define _Standard_NoSuchObject_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_DefineException.hxx>
#include <Standard_SStream.hxx>
#include <Standard_DomainError.hxx>
@@ -17,7 +17,6 @@
#ifndef _Standard_NotImplemented_HeaderFile
#define _Standard_NotImplemented_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_DefineException.hxx>
#include <Standard_SStream.hxx>
#include <Standard_ProgramError.hxx>
@@ -17,7 +17,6 @@
#ifndef _Standard_NullObject_HeaderFile
#define _Standard_NullObject_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_DefineException.hxx>
#include <Standard_SStream.hxx>
#include <Standard_DomainError.hxx>
@@ -17,7 +17,6 @@
#ifndef _Standard_NullValue_HeaderFile
#define _Standard_NullValue_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_DefineException.hxx>
#include <Standard_SStream.hxx>
#include <Standard_RangeError.hxx>
@@ -17,7 +17,6 @@
#ifndef _Standard_NumericError_HeaderFile
#define _Standard_NumericError_HeaderFile
#include <Standard_Type.hxx>
#include <Standard_DefineException.hxx>
#include <Standard_SStream.hxx>
#include <Standard_Failure.hxx>

Some files were not shown because too many files have changed in this diff Show More