问题描述
客户端在服务器上创建远程对象
客户端调用该对象上的方法
该方法抛出异常
client creates a remote object on the server
client calls a method on that object
that method throws an exception
我该如何处理来自客户的例外。
----------------------------------------- -------------------------------------------------- ---
更具体地说,我正在尝试创建一个登录系统,客户端在服务器上创建一个远程对象来查询数据库。我们以ValidateUser方法(字符串用户名,字符串密码)为例。我希望方法在凭证正确时返回true,否则返回false。但是如果抛出任何异常(比如连接到数据库的问题),我想在服务器应用程序上捕获它们并相应地处理它们。
How do I handle that exception from the client.
----------------------------------------------------------------------------------------------
To be more specific I am trying to create a login system where the client creates a remote object on the server to query a database. Let's take the method ValidateUser(string username, string password) for example. I want the method to return true if the credentials are correct and false if they are not. But if any exceptions are thrown (say a problem connecting to the database) I want to catch them on the server application and handle them accordingly.
我想到的一个解决方案是返回一个具有该方法的所有可能结果的对象,例如:
One solution I have thought of is to return an object with all of the possible results of the method e.g.:
class MethodResults
{bool exceptionThrown;
string exceptionMessage;
bool validUser ;
等。
}
class MethodResults
{
bool exceptionThrown;
string exceptionMessage;
bool validUser;
etc.
}
但这似乎不是正确的做法。它确实有效,但它是一种如此糟糕的技术,我无法忍受它。
but that just does not seem like the right way to do it. It does work but it's such a bad technique I can't stand it.
那么在客户端应用程序上捕获应用程序异常的正确方法是什么。
So what is the right way to catch application exceptions on the client application.
推荐答案
Try
Catch Ex as Exception
End Try
OR
Try
Catch ex As Exception
Finnaly
End try
这篇关于远程处理时如何处理异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!