2015-02-04 3 views
0
catch (Exception ex) 
    { 
    _errorCode = ErrorCodes.SqlGeneralError; 
    CommonTools.vAddToLog(ex, _errorCode, _userID); 
    throw new JOVALException(_errorCode); 
} 

내가 (JOVALException)그러나 예외가 발생하는 경우가 열려 "아니오 소스 가능"페이지라는 사용자 정의 예외 오류를 처리하는 코드의 평화를 사용하고 저를 telled 즉 없음 스택 추적이 비어 있음 어떻게이 문제를 해결할 수 있습니까?예외 (취급)

편집 여기

public JOVALException(ErrorCodes _errCode, String _message = "") 
     { 
      ErrMessage = _message; 
      ErrCode = _errCode; 

     } 

내 생성자는 어떻게 수정할 수 있습니까?

답변

0

내가 생성자를 추가하여이 JOVALException 클래스를 수정하는 것이 좋습니다 것 :

public class JOVALException: Exception { 
    ... 
    // Note Exception "innerException" argument 
    public JOVALException(ErrorCodes _errCode, Exception innerException, String _message = "") 
     : base(_message, inner) { 
     ... 
    } 
    } 

또 다른 문제 : 코드 중복 ErrMessage 이후

ErrMessage = _message; 

을 피하려고, 사실, Message 증진; 기본 클래스 생성자을 호출하면됩니다.

catch (Exception ex) 
    { 
    _errorCode = ErrorCodes.SqlGeneralError; 
    CommonTools.vAddToLog(ex, _errorCode, _userID); 
    throw new JOVALException(_errorCode, ex); // <- Note "ex" 
    } 
1

throw new JOVALException(_errorCode);으로 전화하면 원본 오류의 스택 추적이 손실됩니다.

그냥 수행

throw; 

당신은 당신이 약간 클래스를 수정해야거야 JOVALException 던져해야하는 경우 :

class JOVALException : Exception 
{ 
    public JOVALException(string errorCode, Exception innerException) 
     : base(errorCode, innerException) 
    { 

    } 
} 

을 그리고 예 :

try 
{ 
     int i = 0; 
     int foo = i/i; 
} 
catch (Exception ex) 
{ 
    _errorCode = ErrorCodes.SqlGeneralError; 
    CommonTools.vAddToLog(ex, _errorCode, _userID); 
    throw new JOVALException(_errorCode, ex); 
} 
+1

는하지만 "JOVALException"입니다 호출 방법을 알려줄 필요가! –

+0

@RaedAlsaleh 그렇습니다 ... – DGibbs

5

넣어 JOVALExceptionex을 입력하고 inner exception으로 입력하십시오.

public JOVALException(ErrorCodes _errCode, String _message = "", 
    Exception innerException = null) : base(_message, innerException) 
{ 
    ErrMessage = _message; 
    ErrCode = _errCode; 
} 
+0

하지만 내부 예외는 readonly 속성입니다 –

+0

@RaedAlsaleh 내부 예외를 전달하는 기본 생성자를 호출하는 JOVALException에 적절한 생성자를 추가해야합니다. 링크를 참조하십시오. –

+2

문서; 그것은 작동합니다. >.> –