Posts

Showing posts with the label exception-handling

Throw exception in test method using MSTest

Throw exception in test method using MSTest I'm using MSTest to write test cases for my application. I have a method where files are moved from one directory to another directory. Now when I run code coverage, it shows that the catch block is not covered in code coverage. This is my code as below. class Class1 { public virtual bool MoveFiles( string fileName) { bool retVal = false; try { string sourcePath = "PathSource"; string destinationPath = "DestPath"; if (Directory.Exists(sourcePath) && Directory.Exists(destinationPath)) { string finalPath = sourcePath + "\" + fileName ; if (Directory.Exists(finalPath)) { File.Move(finalPath, destinationPath); retVal = true; } } } ...

c# UserControl constructor don't throws exceptions as expected

c# UserControl constructor don't throws exceptions as expected This is my WinForm solution entry point in Program.cs: try { Application.Run(new MainForm()); } catch (Exception e) { Log.error(e.ToString()); ErrorHandlerForm abend = new ErrorHandlerForm(e); abend.ShowDialog(); } It works fine, every exception thrown in my solution is gracefully handled! But today I found an issue: My program don't catch exceptions that occurs in UserControls construstors! It simply crash to windows with the ugly system prompt (or it shows the error in the VisualStudio if i am in debug mode). I don't understand this behaviour and I have no idea how to fix it, I want to catch those exception in my catch block. what error do you get in Visual studio when in debug mode ? – Prany Jul 1 at 17:13 ...

BMI with exception handling python

BMI with exception handling python I need help with this code I am trying to apply, a short time ago I ran a bmi calculator in index and now I am trying to update that code with exception handling. So far the portions don't give me errors they just run strangely together. For example, when it prompts "Enter the user's name or '0' to quit" it doesn't actually end the process it continues on to the exception process. Can someone help me write this more efficiently. here is my code this is updated, the issue I am specifically having now is the program is not terminating when the user enters '0': def bmi_calculator(): end = False print("Welcome to the BMI Calculator!") while end == False: user = input("Enter student's name or '0' to quit: ") if user == "0": print("end of report!") end = True else: print("Lets gather your information,", user) break ...

java.lang.IllegalStateException: sending message to a Handler on a dead thread

java.lang.IllegalStateException: sending message to a Handler on a dead thread I have developed a game which makes use of lots of handlers.I am using admob interstitial ads.When a game level is cleared i show the interstitial ad but when i close the ad exception is thrown which i am not able to figure out The Exception is thrown only when i close the interstitial ad. Code : collectORCancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { isCollectPressed = true; soundPlayer.playClickSound(); Utils.getInstance().playClickAnimation(v); handler.postDelayed(new Runnable() { @Override public void run() { addCandy(); dialog.dismiss(); getActivity().getSupportFragmentManager().popBackStack(); handler.postDelayed(new Runnable() { @Override public void run() { Utils.g...