异常治疗的最佳实践(Exception treatment best practice)
我想知道哪个是进行异常处理的最佳方法,因为在我的
Try
语句中,我有很多验证,如果我在那里得到一些Exception
,我的Catch
语句可以告诉我发生了什么,但我怎么能知道哪个字段出现Exception
?示例代码
try { // If I get a Exception when converting to number, // I will understand the error // but how could I know where in my `Try` statement was the error ? int valor = Convert.ToInt32(xmlnode[i].ChildNodes.Item(2).InnerText.Trim()); // A Lot of another validations here } Catch(Exception e) { this.LogInformation(e.Message); }
I would like to know which is the best way to make a Exception treatment, because inside my
Try
statement, I have a lot of validations, and if I get someException
there, myCatch
statement can tell me what happens, but how could I know in which field occurs theException
?Sample Code
try { // If I get a Exception when converting to number, // I will understand the error // but how could I know where in my `Try` statement was the error ? int valor = Convert.ToInt32(xmlnode[i].ChildNodes.Item(2).InnerText.Trim()); // A Lot of another validations here } Catch(Exception e) { this.LogInformation(e.Message); }
原文:https://stackoverflow.com/questions/17472268
更新时间:2022-03-15 14:03
最满意答案
我结束了通过使用下面的代码
ImageButton imageButton = (ImageButton) toolbar.findViewById(R.id.shareButton); imageButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { } });
我不知道这是否正确的方式,但它的工作原理
I ended up by using the following code
ImageButton imageButton = (ImageButton) toolbar.findViewById(R.id.shareButton); imageButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { } });
I don't know if this the correct way.But it works
相关问答
更多-
我有同样的问题,你和我会告诉你我做了什么来解决它 1)定义toolbar.xml
工具栏和导航(toolbar and navigation on it)[2023-04-28]
尝试这个。 首先,删除implements NavigationView.OnNavigationItemSelectedListener ,并注释掉覆盖的方法和变量。 然后覆盖Activity的onBackPressed()方法,如下所示: @Override public void onBackPressed() { FragmentManager fragmentManager = getFragmentManager(); if (fragmentManager.getBac ...如果你想知道什么时候点击家庭是一个AppCompatActivity那么你应该尝试这样: 首先告诉Android您要使用您的Toolbar作为您的ActionBar : setSupportActionBar(toolbar); 然后设置Home通过setDisplayShowHomeEnabled如下所示: getSupportActionBar().setDisplayShowHomeEnabled(true); 终于听到android.R.id.home上的点击事件像平常一样: @Override ...在点击工具栏中更改图标(Changing icon in Toolbar on click)[2022-05-16]
只需调用setIcon()方法setIcon() 。 在你的情况下, item.setIcon(your drawable) Just call the method setIcon(). in your case, item.setIcon(your drawable)这里为了简化方法,我使用CheckBox作为RecyclerView项目并隐藏它的按钮。 之后,它将像TextView一样工作,但也具有检查更改属性。 然后,我将OnCheckedChangeListener设置OnCheckedChangeListener CheckBox 。 我在每个真正的onCheckedChanged结果上增加一个整数计数器,并在false上减少。 然后通过Interface将该计数器的值传递回基本活动。 在那里检查计数器是否大于0,这将设置项目的可见性。 以下是该任务的参考代码。 ...单击下一个项目时如何显示工具栏(并隐藏当前)?(How to show toolbar ( and hide current ) when click on the next item?)[2022-10-06]
你可以试试这个 $(".element").on('mouseup', function(e){ $('[el-button]').click(function(e){ e.preventDefault(); }); if ( !$('.dm-popover').hasClass('in') ) { var toolbar = $('工具栏项目单击(Toolbar Item Click)[2022-01-15]
我结束了通过使用下面的代码 ImageButton imageButton = (ImageButton) toolbar.findViewById(R.id.shareButton); imageButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { } }); ...请检查您的处理程序isEnable()和isHandled()状态。 Please check your handler isEnable() and isHandled() status.要为工具提示动态设置html,请在目标组件渲染上创建html,然后在更新工具提示的工具提示上设置before show listener。 xtype: 'tbtext', html: 'Hover to see tooltip', listeners: { 'render': function() { Ext.create({ xtype: 'tooltip', target: this.getEl(), li ...试试这段代码 @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManife ...相关文章
更多- Hadoop in Practice
- 微信公众平台开发最佳实践
- java Exception异常处理实例
- Hibernate的最佳实践
- MySQL最佳实践
- Hadoop管理员的十个最佳实践
- 分布式计算开源框架Hadoop入门实践
- 知识源于实践交流
- 【第七章】 对JDBC的支持 之 7.5 集成Spring JDBC及最佳实践 ——跟我学spring3
- EXT4 Store Load For Gird Exception
最新问答
更多- 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
- 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
- OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
- 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
- codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
- 在计算机拍照在哪里进入
- 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
- No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
- 单页应用程序:页面重新加载(Single Page Application: page reload)
- 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
- System.StackOverflow错误(System.StackOverflow error)
- KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
- 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
- android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
- TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
- 企业安全培训的各项内容
- 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
- C#类名中允许哪些字符?(What characters are allowed in C# class name?)
- NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
- 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
- 将多个行和可变行移动到列(moving multiple and variable rows to columns)
- 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
- 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
- Angular $资源不会改变方法(Angular $resource doesn't change method)
- 在Angular 5中不是一个函数(is not a function in Angular 5)
- 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
- 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
- 常见的python rpc和cli接口(Common python rpc and cli interface)
- Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
- 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)