今や、単一のサーバーと多数のクライアントを持つ分散システムを作成し始めました。使用される言語はPythonで、通信はソケットとJSONを使用して行われます。分散システム:クライアント側でサーバー側で発生するエラーを発生させよう
except Exception as e:
jsonResult = {"error":
{
"name":e.__class__.__name__,
"args": e.args
}
}
jsonResult = json.dumps(jsonResult)
jsonResult += "\n"
return jsonResult
そして、このように、クライアント側でそれを上げてみてください:
エラーは、サーバー側で発生した場合、私はこのように、クライアント側にエラークラス名とエラー引数を送ります errorFunc = decodedReply["error"]["name"]
args = decodedReply["error"]["args"]
print (args)
# Builds and appends the argumentstring to the error class-name.
errorFunc += '('
for arg in args:
# Handles when the argument is a string.
if isinstance(arg, str):
errorFunc += '\'' + arg + '\','
else:
errorFunc += arg + ','
# Removes the extra ',' from the string before adding the last ')'.
errorFunc = errorFunc[:-1]
errorFunc += ')'
# Debugging print.
print ("Here: " + errorFunc)
raise exec(errorFunc)
私はこれを行うと、私は私がここに読んだから、エラー
TypeError: exceptions must derive from BaseException
を得る:Error exception must derive from BaseException even when it does (Python 2.7)
私はクラスとして宣言しなければならないようです。それを回避するためにとにかくありますか?例外ではなく、あなたが何かを上げているのpythonによると
あなたは「(プリント 'の出力を表示することができますここでは: "+ errorFunc)'? – Saksow
'ここに:ValueError( 'ABC')' が出力されます。このエラーは、サーバー側で手動で発生させたエラーです。 –
私の答えをチェック – Saksow