コード例 #1
0
ファイル: lwexc.c プロジェクト: FarazShaikh/LikewiseSMB2
void
LWRaise(
    LWException** dest, 
    DWORD code
    )
{
    DWORD ceError;
    char *shortMsg;
    char *longMsg;
    const char* desc = LwWin32ExtErrorToName(code);
    const char* help = LwWin32ExtErrorToDescription(code);

    if (!desc)
    {
        shortMsg = "Undocumented exception";
    }
    if ((ceError = CTAllocateString(desc, &shortMsg)))
    {
	*dest = CreateException(ceError, __FILE__, __LINE__, NULL, NULL);
	return;
    }

    if (!help)
    {
        longMsg = "An undocumented exception has occurred. Please contact Likewise technical support and use the error code to identify this exception.";
    }
    if ((ceError = CTAllocateString(help, &longMsg)))
    {
	*dest = CreateException(ceError, __FILE__, __LINE__, NULL, NULL);
	return;
    }
    
    *dest = CreateException(code, NULL, 0, shortMsg, longMsg);
}
void testThrowFunc() {
  throw new logic_error("by pointer");
  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: throw expression throws a pointer; it should throw a non-pointer value instead [misc-throw-by-value-catch-by-reference]
  logic_ptr tmp = new logic_error("by pointer");
  throw tmp;
  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: throw expression should throw anonymous temporary values instead [misc-throw-by-value-catch-by-reference]
  // CHECK-MESSAGES: :[[@LINE-2]]:9: warning: throw expression throws a pointer; it should throw a non-pointer value instead [misc-throw-by-value-catch-by-reference]
  throw logic_error("by value");
  auto *literal = "test";
  throw logic_error(literal);
  throw "test string literal";
  throw L"throw wide string literal";
  const char *characters = 0;
  throw characters;
  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: throw expression should throw anonymous temporary values instead [misc-throw-by-value-catch-by-reference]
  // CHECK-MESSAGES: :[[@LINE-2]]:9: warning: throw expression throws a pointer; it should throw a non-pointer value instead [misc-throw-by-value-catch-by-reference]
  logic_error lvalue("lvalue");
  throw lvalue;
  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: throw expression should throw anonymous temporary values instead [misc-throw-by-value-catch-by-reference]

  throw move(lvalue);
  int &ex = lastException;
  throw ex;
  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: throw expression should throw anonymous temporary values instead [misc-throw-by-value-catch-by-reference]
  throw CreateException();
}
コード例 #3
0
ファイル: lwexc.c プロジェクト: FarazShaikh/LikewiseSMB2
void
LWReraiseEx(
    LWException** dest,
    LWException** src,
    const char* file,
    unsigned int line
    )
{
    if (dest)
    {
	LWStackFrame* down = malloc(sizeof(*down));

	if (!down)
	{
	    LWHandle(src);
	    *dest = CreateException(ERROR_OUTOFMEMORY, file, line, NULL, NULL);
	}
	else
	{
	    *dest = *src;
	    *src = NULL;
	    
	    *down = (*dest)->stack;
	    (*dest)->stack.file = file;
	    (*dest)->stack.line = line;
	    (*dest)->stack.down = down;
	}
    }
    else
    {
	LWHandle(src);
    }
}
コード例 #4
0
ファイル: ToJSValue.cpp プロジェクト: GuanWen-Chen/gecko-b2g
bool
ToJSValue(JSContext* aCx,
          nsresult aArgument,
          JS::MutableHandle<JS::Value> aValue)
{
  RefPtr<Exception> exception = CreateException(aCx, aArgument);
  return ToJSValue(aCx, exception, aValue);
}
コード例 #5
0
ファイル: Exceptions.cpp プロジェクト: Neil511/gecko-dev
bool
Throw(JSContext* aCx, nsresult aRv, const nsACString& aMessage)
{
  if (aRv == NS_ERROR_UNCATCHABLE_EXCEPTION) {
    // Nuke any existing exception on aCx, to make sure we're uncatchable.
    JS_ClearPendingException(aCx);
    return false;
  }

  if (JS_IsExceptionPending(aCx)) {
    // Don't clobber the existing exception.
    return false;
  }

  CycleCollectedJSRuntime* runtime = CycleCollectedJSRuntime::Get();
  nsCOMPtr<nsIException> existingException = runtime->GetPendingException();
  // Make sure to clear the pending exception now.  Either we're going to reuse
  // it (and we already grabbed it), or we plan to throw something else and this
  // pending exception is no longer relevant.
  runtime->SetPendingException(nullptr);

  // Ignore the pending exception if we have a non-default message passed in.
  if (aMessage.IsEmpty() && existingException) {
    nsresult nr;
    if (NS_SUCCEEDED(existingException->GetResult(&nr)) &&
        aRv == nr) {
      // Reuse the existing exception.
      if (!ThrowExceptionObject(aCx, existingException)) {
        // If we weren't able to throw an exception we're
        // most likely out of memory
        JS_ReportOutOfMemory(aCx);
      }
      return false;
    }
  }

  RefPtr<Exception> finalException = CreateException(aCx, aRv, aMessage);

  MOZ_ASSERT(finalException);
  if (!ThrowExceptionObject(aCx, finalException)) {
    // If we weren't able to throw an exception we're
    // most likely out of memory
    JS_ReportOutOfMemory(aCx);
  }

  return false;
}
コード例 #6
0
ファイル: Exceptions.cpp プロジェクト: LordJZ/gecko-dev
bool
Throw(JSContext* aCx, nsresult aRv, const char* aMessage)
{
  if (aRv == NS_ERROR_UNCATCHABLE_EXCEPTION) {
    // Nuke any existing exception on aCx, to make sure we're uncatchable.
    JS_ClearPendingException(aCx);
    return false;
  }

  if (JS_IsExceptionPending(aCx)) {
    // Don't clobber the existing exception.
    return false;
  }

  CycleCollectedJSRuntime* runtime = CycleCollectedJSRuntime::Get();
  nsCOMPtr<nsIException> existingException = runtime->GetPendingException();
  if (existingException) {
    nsresult nr;
    if (NS_SUCCEEDED(existingException->GetResult(&nr)) && 
        aRv == nr) {
      // Reuse the existing exception.

      // Clear pending exception
      runtime->SetPendingException(nullptr);

      if (!ThrowExceptionObject(aCx, existingException)) {
        // If we weren't able to throw an exception we're
        // most likely out of memory
        JS_ReportOutOfMemory(aCx);
      }
      return false;
    }
  }

  nsRefPtr<Exception> finalException = CreateException(aCx, aRv, aMessage);

  MOZ_ASSERT(finalException);
  if (!ThrowExceptionObject(aCx, finalException)) {
    // If we weren't able to throw an exception we're
    // most likely out of memory
    JS_ReportOutOfMemory(aCx);
  }

  return false;
}
コード例 #7
0
	BOOL SearchElementVisitor::CompareHrefAndSrc(IHTMLElement* pElement, const String& sElementUrl, const String& sCompareToUrl)
	{
		ATLASSERT(pElement != NULL);

		/////////////////////////////////////////////////////////////////////////////////////////////////
		// Step One: compare the links directly.
		if (sElementUrl == sCompareToUrl)
		{
			return TRUE;
		}


		/////////////////////////////////////////////////////////////////////////////////////////////////
		// Step Two: extract the file name from the element url and compare against the value coming from the script.

		// Get the document of the element.
		CComQIPtr<IDispatch> spDisp;
		HRESULT hRes = pElement->get_document(&spDisp);

		CComQIPtr<IHTMLDocument2> spDocument = spDisp;
		if (spDocument == NULL)
		{
			throw CreateException(_T("Can not get the document in HtmlHelpers::CompareHrefAndSrc"));
		}

		// Create a new <A> tag.
		CComQIPtr<IHTMLElement> spNewElement;
		hRes = spDocument->createElement(CComBSTR("a"), &spNewElement);
		if (FAILED(hRes))
		{
			throw CreateException(_T("Can not create a new element in HtmlHelpers::CompareHrefAndSrc"));
		}

		// Set the href attribute in the newly created anchor element.
		hRes = spNewElement->setAttribute(CComBSTR("href"), CComVariant(sElementUrl.c_str()), 0);
		if (FAILED(hRes))
		{
			throw CreateException(_T("Can not set the href in the html element in HtmlHelpers::CompareHrefAndSrc"));
		}

		CComQIPtr<IHTMLAnchorElement> spAnchor = spNewElement;
		if (spAnchor == NULL)
		{
			throw CreateException(_T("Query for IHTMLAnchorElement failed in HtmlHelpers::CompareHrefAndSrc"));
		}

		CComBSTR bstrFileName;
		hRes = spAnchor->get_nameProp(&bstrFileName);
		if (FAILED(hRes) || (bstrFileName == NULL))
		{
			throw CreateException(_T("IHTMLAnchorElement::get_nameProp failed in HtmlHelpers::CompareHrefAndSrc"));
		}

		USES_CONVERSION;
		if (Common::MatchWildcardPattern(W2T(bstrFileName), sCompareToUrl.c_str()))
		{
			// sCompareToUrl is the file name.
			return TRUE;
		}

		return FALSE;
	}
コード例 #8
0
ファイル: lwexc.c プロジェクト: FarazShaikh/LikewiseSMB2
void
LWRaiseEx(
    LWException** dest,
    DWORD code,
    const char* file,
    unsigned int line,
    const char* _shortMsg,
    const char* fmt,
    ...
    )
{
    if (dest)
    {
	DWORD ceError;
	char* shortMsg;
	char* longMsg;
	va_list ap;
	
	va_start(ap, fmt);
	
	if (!_shortMsg)
	{
	    _shortMsg = LwWin32ExtErrorToName(code);
	}
        if (!_shortMsg)
        {
            _shortMsg = "Undocumented exception";
        }

	if (!fmt)
	{
	    fmt = LwWin32ExtErrorToDescription(code);
	}
        if (!fmt)
        {
            fmt = "An undocumented exception has occurred. Please contact Likewise technical support and use the error code to identify this exception.";
        }

	if (_shortMsg)
	{
	    if ((ceError = CTAllocateString(_shortMsg, &shortMsg)))
	    {
		*dest = CreateException(ceError, __FILE__, __LINE__, NULL, NULL);
		return;
	    }
	}
	else
	{
	    shortMsg = NULL;
	}
	    
	if (fmt)
	{
	    if ((ceError = CTAllocateStringPrintfV(&longMsg, fmt, ap)))
	    {
		CTFreeString(shortMsg);
		*dest = CreateException(ceError, __FILE__, __LINE__, NULL, NULL);
		return;
	    }
	}
	else
	{
	    longMsg = NULL;
	}

	*dest = CreateException(code, file, line, shortMsg, longMsg);
    }
}