diff --git a/indra/llui/llclipboard.cpp b/indra/llui/llclipboard.cpp
index 1d18cb2bb039173911f85608e27903314d7d0a01..06fac190ed225ca80f7cf3bddf8564a5acb0d6ec 100644
--- a/indra/llui/llclipboard.cpp
+++ b/indra/llui/llclipboard.cpp
@@ -123,7 +123,15 @@ bool LLClipboard::copyToClipboard(const LLWString &src, S32 pos, S32 len, bool u
 // Concatenate the input string to the LL and the system clipboard
 bool LLClipboard::addToClipboard(const LLWString &src, S32 pos, S32 len, bool use_primary)
 {
-	mString = src.substr(pos, len);
+	try
+	{
+		mString = src.substr(pos, len);
+	}
+	catch (const std::exception& e)
+	{
+		LL_WARNS() << "Can't add the substring to clipboard: " << e.what() << LL_ENDL;
+		return false;
+	}
 	return (use_primary ? LLView::getWindow()->copyTextToPrimary(mString) : LLView::getWindow()->copyTextToClipboard(mString));
 }