远程处理时如何处理异常? [英] How do you handle exceptions when remoting?

查看:111
本文介绍了远程处理时如何处理异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

客户端在服务器上创建远程对象
客户端调用该对象上的方法
该方法抛出异常

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 cactch语句。只有当事情不在我的控制之下时,我才会使用下面的语句和其他一些语句。
示例将与服务器连接并且服务器已关闭。


不确定C#中的代码是什么,但我相信它会很接近

This is what i do.

I try and handle my own code and objects without using the try cactch statement. ONLY when things are out of my control then than i use the statements below and some others.
Example would be conencting to a server and the server is down.


not sure what the code woulf be in C# but i am sure it would be close
Try

Catch Ex as Exception

End Try

OR

 Try 

Catch ex As Exception

Finnaly

End try


这篇关于远程处理时如何处理异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆