exception

How can I mock a void method to throw an exception?

戏子无情 提交于 2020-01-23 04:31:07
问题 I have a structure like this: public class CacheWrapper { private Map<Object, Object> innerMap; public CacheWrapper() { //initialize the innerMap with an instance for an in-memory cache //that works on external server //current implementation is not relevant for the problem innerMap = ...; } public void putInSharedMemory(Object key, Object value) { innerMap.put(key, value); } public Object getFromSharedMemory(Object key) { return innerMap.get(key); } } And my client class (you could say it

Android Webview becomes slow after a certain Exception

空扰寡人 提交于 2020-01-23 03:24:05
问题 After the exception (listed below) occures the Android Webview becomes noticeably slower. Every action within the webview takes five to ten seconds longer to load. The exception randomly happens after reloading a webview. Sometimes it happens after a few reloads and sometimes it takes up to 400 reloads to occur. It only happens on a webview that opens multiple websockets and it has to be tied to the Chrome engine 78.0.3904 and newer Chrome engines since I couldn't reproduce this Exception on

VB.Net Examples of User-Defined Exceptions?

扶醉桌前 提交于 2020-01-23 01:24:09
问题 Very simply put, I am wondering if anybody here can give me an example of a user-defined exception in VB.Net. I already have two examples that I was able to find online, but other than that, I cannot think of any more. I need to find at least 5 to put in my notes, and then submit to my teacher. The two I have so far are: invalid login information (such as improper username or password), and expired credit card information on an online store. Any help would be greatly appreciated. 回答1: The

Throw an exception or return null

丶灬走出姿态 提交于 2020-01-22 21:29:50
问题 If I've got the function below, with two choices private MyObject findBlank() { for (int i = 0; i < pieces.length; i++) { if(pieces[i].isBlank()){ return pieces[i]; } } return null; } private MyObject findBlank() { for (int i = 0; i < pieces.length; i++) { if(pieces[i].isBlank()){ return pieces[i]; } } throw new NoSuchFieldError("No blank piece found!"); } From this method I know that it should always return an object one of the 'pieces' always is isBlank() == true , the return null at the

Can we get LineNumber and ColumnNumber in try block at which exception occured

不打扰是莪最后的温柔 提交于 2020-01-22 18:58:08
问题 I have the below code with which i am able to print the fullclassname,classname,methodname, at which error occured. Also, I am able to print Line-Number but the Line-Number printed is the line at which the variable "LineNumber" is initialized. How can i print the exact LineNumber and ColumnNumber in try block at which error occured? try { SQL Query } catch(Exception e) { String fullClassName = Thread.currentThread().getStackTrace()[1].getClassName(); String className = fullClassName.substring

SQLite - Could not open database file

谁说我不能喝 提交于 2020-01-22 17:57:05
问题 I am coding a Xamarin Android application, and am getting an error when trying to create a SQLite database. Here is my code: string applicationFolderPath = System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "CanFindLocation"); string databaseFileName = System.IO.Path.Combine(applicationFolderPath, "CanFindLocation.db"); SQLite.SQLite3.Config(SQLite.SQLite3.ConfigOption.Serialized); var db = new SQLiteConnection (databaseFileName); Here is the

SQLite - Could not open database file

我们两清 提交于 2020-01-22 17:56:08
问题 I am coding a Xamarin Android application, and am getting an error when trying to create a SQLite database. Here is my code: string applicationFolderPath = System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "CanFindLocation"); string databaseFileName = System.IO.Path.Combine(applicationFolderPath, "CanFindLocation.db"); SQLite.SQLite3.Config(SQLite.SQLite3.ConfigOption.Serialized); var db = new SQLiteConnection (databaseFileName); Here is the

How can I get powershell exception descriptions into a string?

99封情书 提交于 2020-01-22 17:55:46
问题 I want to have access to the same message that Powershell prints when you send an error record to the output stream Example: This is the exception message At C:\Documents and Settings\BillBillington\Desktop\psTest\exThrower.ps1:1 char:6 + throw <<<< (New-Object ArgumentException("This is the exception")); + CategoryInfo : OperationStopped: (:) [], ArgumentException + FullyQualifiedErrorId : This is the exception I when a get the last ErrorRecord by doing $Error[0] I can't seem to figure out

Throwing exception within exception handler

孤街醉人 提交于 2020-01-22 17:43:11
问题 I have a script with an exception handler. This exception handler cleans up a couple connections, prior to the script exiting after an exception. I would like to re-throw the exception from this exception handler so that it is handled by PHP's own last-resort exception handler, where the error is written to PHP's error log, or whatever the default is, as configured in PHP.ini. Unfortunately, this doesn't seem like a possibility, as outlined here: http://www.php.net/manual/en/function.set

Why doesn't a foreach loop work in certain cases?

本小妞迷上赌 提交于 2020-01-22 15:23:47
问题 I was using a foreach loop to go through a list of data to process (removing said data once processed--this was inside a lock). This method caused an ArgumentException now and then. Catching it would have been expensive so I tried tracking down the issue but I couldn't figure it out. I have since switched to a for loop and the problem seems to have went away. Can someone explain what happened? Even with the exception message I don't quite understand what took place behind the scenes. Why is