Fix catching by value

Pointed out by LGTM.
Change-Id: I223655c728305f6f45b3738553da5b7d7a69e8c8
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2134
Reviewed-by: Adrien Destugues <[email protected]>
This commit is contained in:
Murai Takashi
2020-01-21 19:26:22 +00:00
committed by Jérôme Duval
parent 654135466f
commit 992ae400ec
15 changed files with 47 additions and 47 deletions
@@ -518,7 +518,7 @@ GPJob::Write(const char* data, size_t size)
{ {
try { try {
fOutputStream->Write(data, size); fOutputStream->Write(data, size);
} catch (TransportException e) { } catch (TransportException& e) {
fStatus = B_IO_ERROR; fStatus = B_IO_ERROR;
} }
} }
+1 -1
View File
@@ -1124,7 +1124,7 @@ CalcView::_EvaluateThread(void* data)
BString expression(calcView->fExpressionTextView->Text()); BString expression(calcView->fExpressionTextView->Text());
try { try {
result = parser.Evaluate(expression.String()); result = parser.Evaluate(expression.String());
} catch (ParseException e) { } catch (ParseException& e) {
result << e.message.String() << " at " << (e.position + 1); result << e.message.String() << " at " << (e.position + 1);
status = B_ERROR; status = B_ERROR;
} }
+1 -1
View File
@@ -37,7 +37,7 @@ main(int argc, char* argv[])
ExpressionParser parser; ExpressionParser parser;
BString result = parser.Evaluate(expression.String()); BString result = parser.Evaluate(expression.String());
printf("%s\n", result.String()); printf("%s\n", result.String());
} catch (ParseException e) { } catch (ParseException& e) {
printf("%s at %" B_PRId32 "\n", e.message.String(), e.position + 1); printf("%s at %" B_PRId32 "\n", e.message.String(), e.position + 1);
return 1; return 1;
} }
+12 -12
View File
@@ -148,7 +148,7 @@ public:
const char* packageNameString = packageName.String(); const char* packageNameString = packageName.String();
try { try {
fPackageManager->Install(&packageNameString, 1); fPackageManager->Install(&packageNameString, 1);
} catch (BFatalErrorException ex) { } catch (BFatalErrorException& ex) {
BString errorString; BString errorString;
errorString.SetToFormat( errorString.SetToFormat(
"Fatal error occurred while installing package %s: " "Fatal error occurred while installing package %s: "
@@ -162,18 +162,18 @@ public:
_SetDownloadedPackagesState(NONE); _SetDownloadedPackagesState(NONE);
ref->SetState(state); ref->SetState(state);
return ex.Error(); return ex.Error();
} catch (BAbortedByUserException ex) { } catch (BAbortedByUserException& ex) {
fprintf(stderr, "Installation of package " fprintf(stderr, "Installation of package "
"%s aborted by user: %s\n", packageNameString, "%s aborted by user: %s\n", packageNameString,
ex.Message().String()); ex.Message().String());
_SetDownloadedPackagesState(NONE); _SetDownloadedPackagesState(NONE);
ref->SetState(state); ref->SetState(state);
return B_OK; return B_OK;
} catch (BNothingToDoException ex) { } catch (BNothingToDoException& ex) {
fprintf(stderr, "Nothing to do while installing package " fprintf(stderr, "Nothing to do while installing package "
"%s: %s\n", packageNameString, ex.Message().String()); "%s: %s\n", packageNameString, ex.Message().String());
return B_OK; return B_OK;
} catch (BException ex) { } catch (BException& ex) {
fprintf(stderr, "Exception occurred while installing package " fprintf(stderr, "Exception occurred while installing package "
"%s: %s\n", packageNameString, ex.Message().String()); "%s: %s\n", packageNameString, ex.Message().String());
_SetDownloadedPackagesState(NONE); _SetDownloadedPackagesState(NONE);
@@ -273,7 +273,7 @@ public:
const char* packageName = ref->Name().String(); const char* packageName = ref->Name().String();
try { try {
fPackageManager->Uninstall(&packageName, 1); fPackageManager->Uninstall(&packageName, 1);
} catch (BFatalErrorException ex) { } catch (BFatalErrorException& ex) {
BString errorString; BString errorString;
errorString.SetToFormat( errorString.SetToFormat(
"Fatal error occurred while uninstalling package %s: " "Fatal error occurred while uninstalling package %s: "
@@ -286,11 +286,11 @@ public:
alert->Go(); alert->Go();
ref->SetState(state); ref->SetState(state);
return ex.Error(); return ex.Error();
} catch (BAbortedByUserException ex) { } catch (BAbortedByUserException& ex) {
return B_OK; return B_OK;
} catch (BNothingToDoException ex) { } catch (BNothingToDoException& ex) {
return B_OK; return B_OK;
} catch (BException ex) { } catch (BException& ex) {
fprintf(stderr, "Exception occurred while uninstalling package " fprintf(stderr, "Exception occurred while uninstalling package "
"%s: %s\n", packageName, ex.Message().String()); "%s: %s\n", packageName, ex.Message().String());
ref->SetState(state); ref->SetState(state);
@@ -634,11 +634,11 @@ PackageManager::RefreshRepository(const BRepositoryConfig& repoConfig)
status_t result; status_t result;
try { try {
result = BPackageManager::RefreshRepository(repoConfig); result = BPackageManager::RefreshRepository(repoConfig);
} catch (BFatalErrorException ex) { } catch (BFatalErrorException& ex) {
fprintf(stderr, "Fatal error occurred while refreshing repository: " fprintf(stderr, "Fatal error occurred while refreshing repository: "
"%s (%s)\n", ex.Message().String(), ex.Details().String()); "%s (%s)\n", ex.Message().String(), ex.Details().String());
result = ex.Error(); result = ex.Error();
} catch (BException ex) { } catch (BException& ex) {
fprintf(stderr, "Exception occurred while refreshing " fprintf(stderr, "Exception occurred while refreshing "
"repository: %s\n", ex.Message().String()); "repository: %s\n", ex.Message().String());
result = B_ERROR; result = B_ERROR;
@@ -656,12 +656,12 @@ PackageManager::DownloadPackage(const BString& fileURL,
try { try {
result = BPackageManager::DownloadPackage(fileURL, targetEntry, result = BPackageManager::DownloadPackage(fileURL, targetEntry,
checksum); checksum);
} catch (BFatalErrorException ex) { } catch (BFatalErrorException& ex) {
fprintf(stderr, "Fatal error occurred while downloading package: " fprintf(stderr, "Fatal error occurred while downloading package: "
"%s: %s (%s)\n", fileURL.String(), ex.Message().String(), "%s: %s (%s)\n", fileURL.String(), ex.Message().String(),
ex.Details().String()); ex.Details().String());
result = ex.Error(); result = ex.Error();
} catch (BException ex) { } catch (BException& ex) {
fprintf(stderr, "Exception occurred while downloading package " fprintf(stderr, "Exception occurred while downloading package "
"%s: %s\n", fileURL.String(), ex.Message().String()); "%s: %s\n", fileURL.String(), ex.Message().String());
result = B_ERROR; result = B_ERROR;
@@ -130,7 +130,7 @@ LocalPkgDataLoadProcess::RunInternal()
try { try {
manager.Init(PackageManager::B_ADD_INSTALLED_REPOSITORIES manager.Init(PackageManager::B_ADD_INSTALLED_REPOSITORIES
| PackageManager::B_ADD_REMOTE_REPOSITORIES); | PackageManager::B_ADD_REMOTE_REPOSITORIES);
} catch (BException ex) { } catch (BException& ex) {
BString message(B_TRANSLATE("An error occurred while " BString message(B_TRANSLATE("An error occurred while "
"initializing the package manager: %message%")); "initializing the package manager: %message%"));
message.ReplaceFirst("%message%", ex.Message()); message.ReplaceFirst("%message%", ex.Message());
@@ -362,12 +362,12 @@ LocalPkgDataLoadProcess::RunInternal()
it->second->SetSystemDependency(true); it->second->SetSystemDependency(true);
} }
} }
} catch (BFatalErrorException ex) { } catch (BFatalErrorException& ex) {
printf("Fatal exception occurred while resolving system dependencies: " printf("Fatal exception occurred while resolving system dependencies: "
"%s, details: %s\n", strerror(ex.Error()), ex.Details().String()); "%s, details: %s\n", strerror(ex.Error()), ex.Details().String());
} catch (BNothingToDoException) { } catch (BNothingToDoException&) {
// do nothing // do nothing
} catch (BException ex) { } catch (BException& ex) {
printf("Exception occurred while resolving system dependencies: %s\n", printf("Exception occurred while resolving system dependencies: %s\n",
ex.Message().String()); ex.Message().String());
} catch (...) { } catch (...) {
@@ -112,9 +112,9 @@ LocalRepositoryUpdateProcess::_RunForRepositoryName(const BString& repoName,
BRefreshRepositoryRequest refreshRequest(context, repoConfig); BRefreshRepositoryRequest refreshRequest(context, repoConfig);
result = refreshRequest.Process(); result = refreshRequest.Process();
result = B_OK; result = B_OK;
} catch (BFatalErrorException ex) { } catch (BFatalErrorException& ex) {
_NotifyError(ex.Message(), ex.Details()); _NotifyError(ex.Message(), ex.Details());
} catch (BException ex) { } catch (BException& ex) {
_NotifyError(ex.Message()); _NotifyError(ex.Message());
} }
} }
+4 -4
View File
@@ -51,21 +51,21 @@ CheckAction::Perform()
int packageCount = 0; int packageCount = 0;
const char* const packages = ""; const char* const packages = "";
fCheckManager->Update(&packages, packageCount); fCheckManager->Update(&packages, packageCount);
} catch (BFatalErrorException ex) { } catch (BFatalErrorException& ex) {
fprintf(stderr, B_TRANSLATE( fprintf(stderr, B_TRANSLATE(
"Fatal error while checking for updates: %s\n"), "Fatal error while checking for updates: %s\n"),
ex.Message().String()); ex.Message().String());
be_app->PostMessage(kMsgFinalQuit); be_app->PostMessage(kMsgFinalQuit);
return ex.Error(); return ex.Error();
} catch (BAbortedByUserException ex) { } catch (BAbortedByUserException& ex) {
be_app->PostMessage(kMsgFinalQuit); be_app->PostMessage(kMsgFinalQuit);
return B_OK; return B_OK;
} catch (BNothingToDoException ex) { } catch (BNothingToDoException& ex) {
puts(B_TRANSLATE("There were no updates found.")); puts(B_TRANSLATE("There were no updates found."));
fCheckManager->NoUpdatesNotification(); fCheckManager->NoUpdatesNotification();
be_app->PostMessage(kMsgFinalQuit); be_app->PostMessage(kMsgFinalQuit);
return B_OK; return B_OK;
} catch (BException ex) { } catch (BException& ex) {
fprintf(stderr, B_TRANSLATE( fprintf(stderr, B_TRANSLATE(
"Exception occurred while checking for updates: %s\n"), "Exception occurred while checking for updates: %s\n"),
ex.Message().String()); ex.Message().String());
+4 -4
View File
@@ -73,25 +73,25 @@ UpdateAction::Perform(update_type action_request)
throw BException(B_TRANSLATE( throw BException(B_TRANSLATE(
"Invalid update type, cannot continue with updates")); "Invalid update type, cannot continue with updates"));
} catch (BFatalErrorException ex) { } catch (BFatalErrorException& ex) {
fUpdateManager->FinalUpdate(B_TRANSLATE("Updates did not complete"), fUpdateManager->FinalUpdate(B_TRANSLATE("Updates did not complete"),
ex.Message()); ex.Message());
return ex.Error(); return ex.Error();
} catch (BAbortedByUserException ex) { } catch (BAbortedByUserException& ex) {
if (fVerbose) if (fVerbose)
fprintf(stderr, "Updates aborted by user: %s\n", fprintf(stderr, "Updates aborted by user: %s\n",
ex.Message().String()); ex.Message().String());
// No need for a final message since user initiated cancel request // No need for a final message since user initiated cancel request
be_app->PostMessage(kMsgFinalQuit); be_app->PostMessage(kMsgFinalQuit);
return B_OK; return B_OK;
} catch (BNothingToDoException ex) { } catch (BNothingToDoException& ex) {
if (fVerbose) if (fVerbose)
fprintf(stderr, "Nothing to do while updating packages : %s\n", fprintf(stderr, "Nothing to do while updating packages : %s\n",
ex.Message().String()); ex.Message().String());
fUpdateManager->FinalUpdate(B_TRANSLATE("No updates available"), fUpdateManager->FinalUpdate(B_TRANSLATE("No updates available"),
B_TRANSLATE("There were no updates found.")); B_TRANSLATE("There were no updates found."));
return B_OK; return B_OK;
} catch (BException ex) { } catch (BException& ex) {
if (fVerbose) if (fVerbose)
fprintf(stderr, B_TRANSLATE( fprintf(stderr, B_TRANSLATE(
"Exception occurred while updating packages : %s\n"), "Exception occurred while updating packages : %s\n"),
+1 -1
View File
@@ -278,7 +278,7 @@ SymbolLookup::Init()
TRACE(("SymbolLookup::Init(): translated debug area is at: %p, " TRACE(("SymbolLookup::Init(): translated debug area is at: %p, "
"loaded_images: %p\n", fDebugArea, fDebugArea->loaded_images)); "loaded_images: %p\n", fDebugArea, fDebugArea->loaded_images));
} }
} catch (Exception exception) { } catch (Exception& exception) {
// we can live without the debug area // we can live without the debug area
} }
} }
+5 -5
View File
@@ -368,7 +368,7 @@ debug_create_symbol_lookup_context(team_id team, image_id image,
status_t error = lookup->Init(); status_t error = lookup->Init();
if (error != B_OK) if (error != B_OK)
return error; return error;
} catch (BPrivate::Debug::Exception exception) { } catch (BPrivate::Debug::Exception& exception) {
return exception.Error(); return exception.Error();
} }
@@ -429,7 +429,7 @@ debug_lookup_symbol_address(debug_symbol_lookup_context *lookupContext,
exactMatch); exactMatch);
if (error != B_OK) if (error != B_OK)
return error; return error;
} catch (BPrivate::Debug::Exception exception) { } catch (BPrivate::Debug::Exception& exception) {
return exception.Error(); return exception.Error();
} }
@@ -470,7 +470,7 @@ debug_create_image_symbol_iterator(debug_symbol_lookup_context* lookupContext,
status_t error; status_t error;
try { try {
error = lookup->InitSymbolIterator(imageID, *iterator); error = lookup->InitSymbolIterator(imageID, *iterator);
} catch (BPrivate::Debug::Exception exception) { } catch (BPrivate::Debug::Exception& exception) {
error = exception.Error(); error = exception.Error();
} }
@@ -488,7 +488,7 @@ debug_create_image_symbol_iterator(debug_symbol_lookup_context* lookupContext,
try { try {
error = lookup->InitSymbolIteratorByAddress( error = lookup->InitSymbolIteratorByAddress(
(addr_t)imageInfo.text, *iterator); (addr_t)imageInfo.text, *iterator);
} catch (BPrivate::Debug::Exception exception) { } catch (BPrivate::Debug::Exception& exception) {
error = exception.Error(); error = exception.Error();
} }
} }
@@ -565,7 +565,7 @@ debug_next_image_symbol(debug_symbol_iterator* iterator, char* nameBuffer,
_symbolType); _symbolType);
if (error != B_OK) if (error != B_OK)
return error; return error;
} catch (BPrivate::Debug::Exception exception) { } catch (BPrivate::Debug::Exception& exception) {
return exception.Error(); return exception.Error();
} }
@@ -51,7 +51,7 @@ CLanguageFamily::EvaluateExpression(const BString& expression,
try { try {
_output = evaluator.Evaluate(expression, manager, info); _output = evaluator.Evaluate(expression, manager, info);
return B_OK; return B_OK;
} catch (ParseException ex) { } catch (ParseException& ex) {
BString error; BString error;
error.SetToFormat("Parse error at position %" B_PRId32 ": %s", error.SetToFormat("Parse error at position %" B_PRId32 ": %s",
ex.position, ex.message.String()); ex.position, ex.message.String());
@@ -64,7 +64,7 @@ CLanguageFamily::EvaluateExpression(const BString& expression,
return B_NO_MEMORY; return B_NO_MEMORY;
_output->SetToPrimitive(value); _output->SetToPrimitive(value);
return B_BAD_DATA; return B_BAD_DATA;
} catch (ValueNeededException ex) { } catch (ValueNeededException& ex) {
_neededNode = ex.value; _neededNode = ex.value;
} }
+4 -4
View File
@@ -244,7 +244,7 @@ ResourceFile::SetTo(BFile* file, bool clobber)
if (error == B_OK) { if (error == B_OK) {
try { try {
_InitFile(*file, clobber); _InitFile(*file, clobber);
} catch (Exception exception) { } catch (Exception& exception) {
Unset(); Unset();
if (exception.Error() != B_OK) if (exception.Error() != B_OK)
error = exception.Error(); error = exception.Error();
@@ -295,7 +295,7 @@ ResourceFile::InitContainer(ResourcesContainer& container)
_ReadIndex(parseInfo); _ReadIndex(parseInfo);
_ReadInfoTable(parseInfo); _ReadInfoTable(parseInfo);
container.SetModified(false); container.SetModified(false);
} catch (Exception exception) { } catch (Exception& exception) {
if (exception.Error() != B_OK) if (exception.Error() != B_OK)
error = exception.Error(); error = exception.Error();
else else
@@ -1272,7 +1272,7 @@ ResourceFile::_WriteResources(ResourcesContainer& container)
tableEnd->rite_terminator = 0; tableEnd->rite_terminator = 0;
write_exactly(fFile, infoTableOffset, buffer, infoTableSize, write_exactly(fFile, infoTableOffset, buffer, infoTableSize,
"Failed to write info table."); "Failed to write info table.");
} catch (Exception exception) { } catch (Exception& exception) {
if (exception.Error() != B_OK) if (exception.Error() != B_OK)
error = exception.Error(); error = exception.Error();
else else
@@ -1302,7 +1302,7 @@ ResourceFile::_MakeEmptyResourceFile()
fFileType = FILE_TYPE_X86_RESOURCE; fFileType = FILE_TYPE_X86_RESOURCE;
fFile.SetTo(file, kX86ResourcesOffset); fFile.SetTo(file, kX86ResourcesOffset);
fEmptyResources = true; fEmptyResources = true;
} catch (Exception exception) { } catch (Exception& exception) {
if (exception.Error() != B_OK) if (exception.Error() != B_OK)
error = exception.Error(); error = exception.Error();
else else
+2 -2
View File
@@ -1788,7 +1788,7 @@ MoveItem(BEntry* entry, BDirectory* destDir, BPoint* loc, uint32 moveMode,
} catch (status_t error) { } catch (status_t error) {
// no alert, was already taken care of before // no alert, was already taken care of before
return error; return error;
} catch (MoveError error) { } catch (MoveError& error) {
BString errorString(B_TRANSLATE("Error moving \"%name\"")); BString errorString(B_TRANSLATE("Error moving \"%name\""));
errorString.ReplaceFirst("%name", ref.name); errorString.ReplaceFirst("%name", ref.name);
BAlert* alert = new BAlert("", errorString.String(), B_TRANSLATE("OK"), BAlert* alert = new BAlert("", errorString.String(), B_TRANSLATE("OK"),
@@ -1796,7 +1796,7 @@ MoveItem(BEntry* entry, BDirectory* destDir, BPoint* loc, uint32 moveMode,
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE); alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
alert->Go(); alert->Go();
return error.fError; return error.fError;
} catch (FailWithAlert error) { } catch (FailWithAlert& error) {
BString buffer(error.fString); BString buffer(error.fString);
if (error.fName != NULL) if (error.fName != NULL)
buffer.ReplaceFirst("%name", error.fName); buffer.ReplaceFirst("%name", error.fName);
@@ -90,7 +90,7 @@ main(int argc, const char* const* argv)
for (int i = 0; i < packageCount; i++) for (int i = 0; i < packageCount; i++)
installedRepositoryBuilder.AddPackage(packages[i]); installedRepositoryBuilder.AddPackage(packages[i]);
installedRepositoryBuilder.AddToSolver(solver, true); installedRepositoryBuilder.AddToSolver(solver, true);
} catch (BFatalErrorException e) { } catch (BFatalErrorException& e) {
DIE(e.Error(), "%s %s", e.Message().String(), e.Details().String()); DIE(e.Error(), "%s %s", e.Message().String(), e.Details().String());
} }
+1 -1
View File
@@ -696,7 +696,7 @@ main(int argc, const char* const* argv)
min((size_t)SYSTEM_REVISION_LENGTH, strlen(revisionString) + 1), min((size_t)SYSTEM_REVISION_LENGTH, strlen(revisionString) + 1),
"Failed to write revision."); "Failed to write revision.");
} catch (Exception exception) { } catch (Exception& exception) {
if (exception.Description() == "") { if (exception.Description() == "") {
fprintf(stderr, "%s\n", strerror(exception.Error())); fprintf(stderr, "%s\n", strerror(exception.Error()));
} else { } else {