exception-handling

How to check if path is valid without using try-catch?

寵の児 提交于 2020-02-03 18:56:10
问题 I want to check if a folder exists and if not then create it. But I don't know if the path supplied will even valid. When the path is not valid the following happens. string path = "this is an invalid path"; if (!Directory.Exists(path)) Directory.CreateDirectory(path); //Exception thrown here If you supply an invalid path, it will throw a DirectoryNotFoundException exception. How can I stop this exception from occurring? I don't want to use a try-catch. I want to detect that this exception

How to avoid triggering an ArrayIndexOutOfBoundsException while parsing empty positions in a line of CSV?

杀马特。学长 韩版系。学妹 提交于 2020-02-02 14:08:05
问题 String[] values = line.split(","); Long locId = Long.parseLong(replaceQuotes(values[0])); String country = replaceQuotes(values[1]); String region = replaceQuotes(values[2]); String city = replaceQuotes(values[3]); String postalCode = replaceQuotes(values[4]); String latitude = replaceQuotes(values[5]); String longitude = replaceQuotes(values[6]); String metroCode = replaceQuotes(values[7]); String areaCode = replaceQuotes(values[8]); //... public String replaceQuotes(String txt){ txt = txt

Exception Handling in C without C++ in Linux

我的未来我决定 提交于 2020-02-01 04:18:47
问题 Does Linux provide an exception handling in C without resorting to C++? Or, what might be the best way to implement such an exception handling? The goal is to avoid to check return codes for every function called, but do something like in C++ that is thread safe and easily portable. 回答1: I've never heard of Linux providing anything like that, but this page describes a third-party exception handling library for C: http://www.on-time.com/ddj0011.htm I haven't been able to find the download link

How Can I Force Execution to the Catch Block?

给你一囗甜甜゛ 提交于 2020-01-30 04:05:26
问题 I am wondering can try..catch force execution to go into the catch and run code in there? here example code: try { if (AnyConditionTrue) { // run some code } else { // go catch } } catch (Exception) { // run some code here... } 回答1: Rather than throwing an Exception in the else , I would recommend extracting the code from your catch into a method and call that from your else try { if (AnyConditionTrue) { MethodWhenTrue(); } else { HandleError(); } } catch(Exception ex) { HandleError(); } 回答2:

Delphi Exception Handling - How to clean up properly?

ぐ巨炮叔叔 提交于 2020-01-29 06:38:04
问题 I'm looking at some code in an application of ours and came across something a little odd from what I normally do. With exception handling and cleanup, we (as well as many other programmers out there, I'm sure) use a Try/Finally block embedded with a Try/Except block. Now I'm used to the Try/Except inside the Try/Finally like so: Try Try CouldCauseError(X); Except HandleError; end; Finally FreeAndNil(x); end; but this other block of code is reversed as so: Try Try CouldCauseError(X); Finally

Sys.WebForms.PageRequestManagerServerErrorException 12031

戏子无情 提交于 2020-01-28 04:08:45
问题 I'm occasionaly getting the following popup from an AJAX.NET application Sys.WebForms.PageRequestManagerServerErrorException: An Unknown error occurred while processing the request on the server. The status code returned from the server was: 12031 From the Microsoft kb that status code indicates a ERROR_INTERNET_CONNECTION_RESET, but it doesn't state what was the underlying issue the triggered the error in the first place. How can I log/trace/etc the underlying error that generated the popup?

Sys.WebForms.PageRequestManagerServerErrorException 12031

雨燕双飞 提交于 2020-01-28 04:06:05
问题 I'm occasionaly getting the following popup from an AJAX.NET application Sys.WebForms.PageRequestManagerServerErrorException: An Unknown error occurred while processing the request on the server. The status code returned from the server was: 12031 From the Microsoft kb that status code indicates a ERROR_INTERNET_CONNECTION_RESET, but it doesn't state what was the underlying issue the triggered the error in the first place. How can I log/trace/etc the underlying error that generated the popup?

Grails common exception handling in grails 1.1

老子叫甜甜 提交于 2020-01-25 20:38:38
问题 Some one please tell me how to handle RunTimeExceptions in grails version1.1 .I have followed the following tutorial.I could not get it working. http://blog.bruary.net/2008/03/grails-custom-exception-handling.html I have MyException which extends RunTimeException .If this particular exception comes I want show different error page.Is it possible to achieve in grails 1.1 version? 回答1: Can you provide some sample code, where some RuntimeException is thrown? It is difficult to answer your

Properly handling exceptions thrown in a thread or via the WPF dispatcher

江枫思渺然 提交于 2020-01-25 07:30:27
问题 When a thread throws an exception that is unhandled, it terminates. What is the proper way to handle exceptions thrown on threads and how to propogate relevant exception data to other parts of the code that would need to subscribe to notifications? Is there an INotifyThreadPoorlyDesigned interface that I missed somewhere? Same applies for how to handle stuff dispatched to the WPF UI. 回答1: To handle work that throws an exception on a dispatcher thread, simply hook the Application:

Catch axios requests in different files / functions

前提是你 提交于 2020-01-24 22:55:12
问题 I use HTTP requests to get data for my Vue.js application. I have one file called Api.js with the base axios instance: export default () => { return axios.create({ baseURL: apiURL, headers: { Authorization: `JWT ${store.state.token}` } }) } than I have a file called service.js , which contains the functions for the different endpoints: export default { status() { return Api().get('status/') } } In the .vue file I call the method like that. created() { Service.status() .then(response => { //