Search Results

Search found 5463 results on 219 pages for 'runtime'.

Page 25/219 | < Previous Page | 21 22 23 24 25 26 27 28 29 30 31 32  | Next Page >

  • FileVersionInfo.GetVersionInfo getting old version of an exe swapped at runtime

    - by Richard
    I have a program executing in c# that is sometimes updated while it is running by swapping the exe to a new one. I want the program to routinely check if it has been updated and if so, restart. I use the following function to do this. public static bool DoINeedToRestart(string exe_name) { Version cur_version = new Version(MainProgram.StartVersion); Version file_version = new Version(GetProductVersion(exe_name)); MessageBox.Show("Comparing cur_version " + cur_version.ToString() + " with " + file_version.ToString()); if (file_version > cur_version) { return true; } return false; } public static string GetProductVersion(string path_name) { FileVersionInfo myFI = FileVersionInfo.GetVersionInfo(path_name); return myFI.FileVersion; } MainProgram.StartVersion is set when the program is started to be the current version using the GetProductVersion(exe_name) exe_name is set to be the name of the executable that is being updated. The problem I have is once the MainProgram.exe file has been updated (I verify this manually by looking at the file properties and checking the file version), the GetProductVersion still returns the old file version and I have no idea why! Any help is greatly appreciated.

    Read the article

  • c# getting file version of a swapped exe at runtime

    - by Richard
    I have a program executing in c# that is sometimes updated while it is running by swapping the exe to a new one. I want the program to routinely check if it has been updated and if so, restart. I use the following function to do this. public static bool DoINeedToRestart(string exe_name) { Version cur_version = new Version(MainProgram.StartVersion); Version file_version = new Version(GetProductVersion(exe_name)); MessageBox.Show("Comparing cur_version " + cur_version.ToString() + " with " + file_version.ToString()); if (file_version > cur_version) { return true; } return false; } public static string GetProductVersion(string path_name) { FileVersionInfo myFI = FileVersionInfo.GetVersionInfo(path_name); return myFI.FileVersion; } StartVersion is set when the program is started to be the current version using the GetProductVersion(exe_name). exe_name is set to be the name of the executable that is being updated. The problem I have is once the MainProgram.exe file has been updated (I verify this manually by looking at the file properties and checking the file version), the GetProductVersion still returns the old file version and I have no idea why! Any help is greatly appreciated.

    Read the article

  • Scala isn't allowing me to execute a batch file whose path contains spaces.Same Java code does.What

    - by Geo
    Here's the code I have: var commandsBuffer = List[String]() commandsBuffer ::= "cmd.exe" commandsBuffer ::= "/c" commandsBuffer ::= '"'+vcVarsAll.getAbsolutePath+'"' commandsBuffer ::= "&&" otherCommands.foreach(c => commandsBuffer ::= c) val asArray = commandsBuffer.reverse.toArray val processOutput = processutils.Proc.executeCommand(asArray,true) return processOutput otherCommands is an Array[String], containing the following elements: vcbuild /rebuild path to a .sln file vcVarsAll contains the path to Visual Studio's vcvarsall.bat. It's path is C:\tools\microsoft visual studio 2005\vc\vcvarsall.bat. The error I receive is: 'c:\Tools\Microsoft' is not recognized as an internal or external command, operable program or batch file.. The processutils.Proc.executeCommand has the following implementation: def executeCommand(params:Array[String],display:Boolean):(String,String) = { val process = java.lang.Runtime.getRuntime.exec(params) val outStream = process.getInputStream val errStream = process.getErrorStream ... } The same code, executed from Java/Groovy works. What am I doing wrong?

    Read the article

  • organize using directives, re-run tests?

    - by Sarah Vessels
    Before making a commit, I prefer to run all hundred-something unit tests in my C# Solution, since they only take a couple minutes to run. However, if I've already run them all, all is well, and then I decide to organize the using directives in my Solution, is it really necessary to re-run the unit tests? I have a macro that goes through all files in the Solution and runs Visual Studio's 'Remove and Sort' command on each. In my understanding, so long as all projects still build after using directives are changed around, things should be fine at runtime, too. Is this correct thinking?

    Read the article

  • JAVA and how to execute user-code

    - by Parhs
    Hello. I am building a tool which should do a diagnosis based on some values... It should be user extensible so hardcoding the conditions isnt a solution... Suppose that we have a blood test... example ... WBC , ALDO ... And i want the user to be able to write somehow scripts if (WBC.between(4,10) && ALDO.greater(5) || SOMETHINGELESE.isTrue()) ..... diagnosis="MPLAMPLA"... The problem is 1)Write my parser 2)Or try to find something that executes user conditionals at runtime and customize it.. 3)another way Please help,ideas needed!

    Read the article

  • Problem with starting OpenOffice service (soffice) from Java (command working in commandline, but no

    - by Shervin
    I want to exceute a simple command which works from the shell but doesn't work from Java. This is the command I want to execute, which works fine: soffice -headless "-accept=socket,host=localhost,port=8100;urp;" This is the code I am excecuting from Java trying to run this command: String[] commands = new String[] {"soffice","-headless","\"-accept=socket,host=localhost,port=8100;urp;\""}; Process process = Runtime.getRuntime().exec(commands) int code = process.waitFor(); if(code == 0) System.out.println("Commands executed successfully"); When I run this program I get "Commands executed successfully". However the process is not running when the program finishes. Is it possible that the JVM kills the program after it has run? Why doesn't this work?

    Read the article

  • C# Changing class method at run-time

    - by Flavio
    Hi, I need to extend the behavior of an instance, but I don't have access to the original source code of that instance. For example: /* I don't have the source code for this class, only the runtime instance */ Class AB { public void execute(); } in my code I would to intercept every call to execute, compute some sutff and then call the original execute, something like /* This is how I would like to modify the method invokation */ SomeType m_OrgExecute; { AB a = new AB(); m_OrgExecute = GetByReflection( a.execute ); a.execute = MyExecute; } void MyExecute() { System.Console.Writeln( "In MyExecute" ); m_OrgExecute(); } Is that possible? Does anyone have a solution for this problem?

    Read the article

  • Trying to load a DLL with LoadLibrary and get R6034 "An application has made an attempt to load the

    - by nonoitall
    I'm writing a wrapper program that loads Winamp input plugins. I've got it working well so far with quite a few plugins, but for some others, I get an error message at runtime when I attempt to call LoadLibrary on the plugin's DLL. (It seems to happen mostly with plugins that were included with Winamp.) A dialog appears and gives me the error code and message above. This happens, for example, with the in_flac.dll and in_mp3.dll plugins (which come with Winamp). Any ideas on how I can remedy this situation?

    Read the article

  • Retrieving/simulating run-time "layer" functionality in Flash under ActionScript 3.

    - by Triynko
    Are there any AS3 classes to help arrange objects into layers, like in the designer, such that the objects all have the same parent? Obviously, I can use container clips to simulate layers, but I specifically want this kind of functionality for objects that have the same parent. My understanding is that the design-time notion of layers does not exist at run-time, and objects just have a depth index. I'm creating a class to simulate layering functionality with a single parent, but if one already exists, I'd like to check it out. On a side note... how do design-time layer masks manifest themselves at runtime in AS3? I thought maybe all objects on the masked layer share the same mask object, but the "mask" property appears to be null for all objects on the masked layer, even though they share the same parent timeline as the unmasked objects (i.e. unmasked layer object parent == masked layer object parent; therefore, no masked subcontainers appear to be in use).

    Read the article

  • Template and Themes in WPF through Custom Xaml Files

    - by AKRamkumar
    I have an application where I give my user Widgets. Suppose my user wants to customize the layout of the widgets. For example, I have a clock that is green. In Xaml, to add an animation around the clock would be easy. How could i make it such that at runtime, my application reads a layout.xaml file. Loads it and parses all the gradients and xaml. But still be able to use my widget in there. EG <Layout> <Grid> <!-- Grid Definitions or Animations or Whatever--> <Clock/> <!-- They need to be able to simply use this and my applications needs to read this--> </Grid> </Layout>

    Read the article

  • Speed up the loop operation in R

    - by Kay
    Hi, i have a big performance problem in R. I wrote a function that iterates over an data.frame object. It simply adds a new col to a data.frame and accumulate sth. (simple operation). The data.frame has round about 850.000 rows. My PC is still working about 10h now and i have no idea about the runtime. dayloop2 <- function(temp){ for (i in 1:nrow(temp)){ temp[i,10] <- i if (i > 1) { if ((temp[i,6] == temp[i-1,6]) & (temp[i,3] == temp[i-1,3])) { temp[i,10] <- temp[i,9] + temp[i-1,10] } else { temp[i,10] <- temp[i,9] } } else { temp[i,10] <- temp[i,9] } } names(temp)[names(temp) == "V10"] <- "Kumm." return(temp) } Any ideas how to speed up this operation ?

    Read the article

  • Why does my program crash after running this particular function?

    - by Tux
    Whenever I type the command to run this function in my program, it runs and then crashes saying: "The application has requested the Runtime to terminate it in an unusal way." Why does it do this? Thanks in advance, Johnny void showInventory(player& obj) { // By Johnny :D std::cout << "\nINVENTORY:\n"; for(int i = 0; i < 20; i++) { std::cout << obj.getItem(i); i++; std::cout << "\t\t\t" << obj.getItem(i) << "\n"; i++; } } std::string getItem(int i) { return inventory[i]; }

    Read the article

  • Creating/compling .net data class within an application

    - by MrTelly
    Is there a pattern, Xml structure, architecture technique we can use to create simple data holder class code that we can deserialise to/from and do that at runtime? We're in the early design stage of a .Net project and one of our goals is to make the resulting system extensible through configuration without needing a developer. We need to support new sources of data, typcially delivered as Xml messages. Currently we convert/deserialise the messages into simple classes and then use an already existing language which can manipulate those classes as we need. That works well when you have a developer to map the Xml to simple class, create the class and then write the deserialisation, but it's not extensible for for an administrator. Our target user audience is high end DBA and/or network admin - people who can handle Xml but may not know C#.

    Read the article

  • Programatically Add a AnnotationSessionFactoryBean

    - by user146714
    Hi, I have a class that implements BeanDefinitionRegistryPostProcessor. I am trying to add an AnnotationSessionFactoryBean to my Spring Context in either postProcessBeanFactory or postProcessBeanDefinitionRegistry. I need to do this programatically so that I can configure the object at runtime. I am trying to do: @Override public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry bdr) throws BeansException { RootBeanDefinition bd = new RootBeanDefinition( AnnotationSessionFactoryBean.class); // fails here.. can not cast AnnotationSessionFactoryBean asfb = (AnnotationSessionFactoryBean)bd; bdr.registerBeanDefinition("sessionFactory", asfb); thanks for your help --updated with solution: had to do a: GenericBeanDefinition bd = new GenericBeanDefinition(); bd.setBeanClass(AnnotationSessionFactoryBean.class); bd.getPropertyValues().add("dataSource", dataSource); bdr.registerBeanDefinition("sessionFactory", bd);

    Read the article

  • Video encoding by servlet with MEncoder

    - by Andrey
    Hello. I was developing an application for video encoding on the server and got a problem with encoding video with MEncoder. This decoder doesn't work correctly when runned by a command line with Runtime.getRuntime().exec(“D:\mencoder\mnc\mencoder.exe video1.avi -o outvideo1.flv -of lavf -oac mp3lame -lameopts abr:br=64 -srate 22050 -ovc lavc -lavcopts vcodec=flv:vbitrate=300:mbd=2:mv0:trell:v4mv:cbp:last_pred=3 -vf scale=320:240,harddup -quiet”) ; The decoder launches and works in windows console with my parameters, but when it's run from a servlet it just hangs in process list and doesn't do anything before the web-server is stopped. When trying to use decoder from a simple java applcation, it runs correctly. Thanks for help.

    Read the article

  • calling database driver in java app [basically a swing app]

    - by user993250
    I have made a java application that allows a user to choose from certain standards and then allows him to customize those standards according to his needs. Now, the customization [via a swing application] that has been made needs to be persistent. For this we use a database [mysql/access] and hook it to the application so that with each customization made, a table [if non-existent] is created [thus making it runtime and we can not pre-determine the table names or the keys of table etc] and an appropriate entry in the table is made. I have written the driver for this connection. How do I call it in the java application and what approach should I take? I would much appreciate that if somebody can refer me some example that not only shows a sample connection being made via driver but its appropriate calls to the database as well so that i can use it as a guide.

    Read the article

  • How to execute unknown functions from dynamic load libraries?

    - by activenightly
    It's easy to load functions from dynamic libraries when you know this function in design time. just do something like this: int (*fn)(int); l0 = dlopen("./libfoo.so", RTLD_LAZY); if (!l0) { fprintf(stderr, "l0 %s\n", dlerror()); return 1; } fn = (int (*)(int))dlsym(l0, "foo"); if ((error = dlerror()) != NULL) { fprintf(stderr, "fn:%s\n", error); return 1; } x=(*fn)(y); ... How to execute library function when it's unknown in design time? In runtime you have a function name and array of arguments pointers and array of arguments sizes: char* fn_name="foo"; int foo_argc; void* foo_argv[]; int foo_argv_size[]; In scripting language it's a piece a cake task, but how to implement this nicely in c++?

    Read the article

  • Why do dicts of defaultdict(int)'s use so much memory? (and other simple python performance question

    - by dukhat
    import numpy as num from collections import defaultdict topKeys = range(16384) keys = range(8192) table = dict((k,defaultdict(int)) for k in topKeys) dat = num.zeros((16384,8192), dtype="int32") print "looping begins" #how much memory should this use? I think it shouldn't use more that a few #times the memory required to hold (16384*8192) int32's (512 mb), but #it uses 11 GB! for k in topKeys: for j in keys: dat[k,j] = table[k][j] print "done" What is going on here? Furthermore, this similar script takes eons to run compared to the first one, and also uses an absurd quantity of memory. topKeys = range(16384) keys = range(8192) table = [(j,0) for k in topKeys for j in keys] I guess python ints might be 64 bit ints, which would account for some of this, but do these relatively natural and simple constructions really produce such a massive overhead? I guess these scripts show that they do, so my question is: what exactly is causing the high memory usage in the first script and the long runtime and high memory usage of the second script and is there any way to avoid these costs?

    Read the article

  • wcf callback exception after updating to .net 4.0

    - by James
    I have a wcf service that uses callbacks with DualHttpBindings. The service pushes back a datatable of search results the client (for a long running search) as it finds them. This worked fine in .Net 3.5. Since I updated to .Net 4.0, it bombs out with a System.Runtime.FatalException that actually kills the IIS worker process. I have no idea how to even go about starting to fix this. Any recommendations appreciated. The info from the resulting event log is pasted below. An unhandled exception occurred and the process was terminated. Application ID: /LM/W3SVC/2/ROOT/CP Process ID: 5284 Exception: System.Runtime.FatalException Message: Object reference not set to an instance of an object. StackTrace: at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc) at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet) at System.ServiceModel.Dispatcher.ChannelHandler.DispatchAndReleasePump(RequestContext request, Boolean cleanThread, OperationContext currentOperationContext) at System.ServiceModel.Dispatcher.ChannelHandler.HandleRequest(RequestContext request, OperationContext currentOperationContext) at System.ServiceModel.Dispatcher.ChannelHandler.AsyncMessagePump(IAsyncResult result) at System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result) at System.Runtime.AsyncResult.Complete(Boolean completedSynchronously) at System.Runtime.InputQueue1.AsyncQueueReader.Set(Item item) at System.Runtime.InputQueue1.Dispatch() at System.ServiceModel.Channels.ReliableDuplexSessionChannel.ProcessDuplexMessage(WsrmMessageInfo info) at System.ServiceModel.Channels.ReliableDuplexSessionChannel.HandleReceiveComplete(IAsyncResult result) at System.ServiceModel.Channels.ReliableDuplexSessionChannel.OnReceiveCompletedStatic(IAsyncResult result) at System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result) at System.Runtime.AsyncResult.Complete(Boolean completedSynchronously) at System.ServiceModel.Channels.ReliableChannelBinder1.InputAsyncResult1.OnInputComplete(IAsyncResult result) at System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result) at System.Runtime.AsyncResult.Complete(Boolean completedSynchronously) at System.Runtime.InputQueue1.AsyncQueueReader.Set(Item item) at System.Runtime.InputQueue1.Dispatch() at System.Runtime.IOThreadScheduler.ScheduledOverlapped.IOCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped) at System.Runtime.Fx.IOCompletionThunk.UnhandledExceptionFrame(UInt32 error, UInt32 bytesRead, NativeOverlapped* nativeOverlapped) at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP) InnerException: * System.NullReferenceException* Message: Object reference not set to an instance of an object. StackTrace: at System.Web.HttpApplication.ThreadContext.Enter(Boolean setImpersonationContext) at System.Web.HttpApplication.OnThreadEnterPrivate(Boolean setImpersonationContext) at System.Web.AspNetSynchronizationContext.CallCallbackPossiblyUnderLock(SendOrPostCallback callback, Object state) at System.Web.AspNetSynchronizationContext.CallCallback(SendOrPostCallback callback, Object state) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc)

    Read the article

  • mod_mono 'Service Temporarily Unavailable' issue

    - by Charlie Somerville
    I've deployed an ASP.NET web application on a Linux (Debian) server running Apache 2.2 and mod_mono 1.9 It's working well, however Mono occasionally segfaults and uses the entire CPU which causes the website to stop working and display 'Service Temporarily Unavailable' Killing mono fixes it, but obviously this isn't a good solution. I tailed the system log after this happened and I saw the following error messages from the kernel: Apr 20 01:49:37 charliesomerville kernel: [1596436.204158] mono[17909]: segfault at b645f671 ip b645f671 sp b4ffb604 error 4<6>mono[19047]: segfault at b645f66e ip b645f66e sp b4bf7604 error 4<6>mono[18017]: segfault at b645f66e ip b645f66e sp b52fe604 error 4<6>mono[19668]: segfault at b645f5e6 ip b645f5e6 sp b48f4604 error 4<6>mono[22565]: segfault at b645f674 ip b645f674 sp b45f1604 error 4<6>mono[17700]: segfault at b645f661 ip b645f661 sp b51fd604 error 4<6>mono[19596]: segfault at b645f5e6 ip b645f5e6 sp b49f5604 error 4 Apr 20 01:49:37 charliesomerville kernel: [1596436.208172] mono[23219]: segfault at b645f66e ip b645f66e sp b44f0604 error 4 At the end of Apache's error.log are the following errors: [Tue Apr 20 03:10:23 2010] [error] (70014)End of file found: read_data failed [Tue Apr 20 03:10:23 2010] [error] Command stream corrupted, last command was 1 [Tue Apr 20 03:10:23 2010] [error] Command stream corrupted, last command was 1 [Tue Apr 20 03:10:23 2010] [error] Command stream corrupted, last command was 1 System.ArgumentNullException: null key Parameter name: key at System.Collections.Hashtable.get_Item (System.Object key) [0x00000] at System.Runtime.Serialization.SerializationCallbacks.GetSerializationCallbacks (System.Type t) [0x00000] at System.Runtime.Serialization.ObjectManager.RaiseOnDeserializingEvent (System.Object obj) [0x00000] at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadObjectContent (System.IO.BinaryReader reader, System.Runtime.Serialization.Formatters.Binary.TypeMetadata metadata, Int64 objectId, System.Object& objectInstance, System.Runtime.Serialization.SerializationInfo& info) [0x00000] at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadObjectInstance (System.IO.BinaryReader reader, Boolean isRuntimeObject, Boolean hasTypeInfo, System.Int64& objectId, System.Object& value, System.Runtime.Serialization.SerializationInfo& info) [0x00000] at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadObject (BinaryElement element, System.IO.BinaryReader reader, System.Int64& objectId, System.Object& value, System.Runtime.Serialization.SerializationInfo& info) [0x00000] at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadNextObject (System.IO.BinaryReader reader) [0x00000] at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadObjectGraph (System.IO.BinaryReader reader, Boolean readHeaders, System.Object& result, System.Runtime.Remoting.Messaging.Header[]& headers) [0x00000] at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.NoCheckDeserialize (System.IO.Stream serializationStream, System.Runtime.Remoting.Messaging.HeaderHandler handler) [0x00000] at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize (System.IO.Stream serializationStream) [0x00000] at System.Runtime.Remoting.Channels.CADSerializer.DeserializeObject (System.IO.MemoryStream mem) [0x00000] at System.Runtime.Remoting.RemotingServices.GetDomainProxy (System.AppDomain domain) [0x00000] at System.AppDomain.CreateDomain (System.String friendlyName, System.Security.Policy.Evidence securityInfo, System.AppDomainSetup info) [0x00000] at System.Web.Hosting.ApplicationHost.CreateApplicationHost (System.Type hostType, System.String virtualDir, System.String physicalDir) [0x00000] at Mono.WebServer.VPathToHost.CreateHost (Mono.WebServer.ApplicationServer server, Mono.WebServer.WebSource webSource) [0x00000] at Mono.WebServer.ApplicationServer.GetApplicationForPath (System.String vhost, Int32 port, System.String path, Boolean defaultToRoot) [0x00000] at (wrapper remoting-invoke-with-check) Mono.WebServer.ApplicationServer:GetApplicationForPath (string,int,string,bool) at Mono.WebServer.ModMonoWorker.GetOrCreateApplication (System.String vhost, Int32 port, System.String filepath, System.String virt) [0x00000] at Mono.WebServer.ModMonoWorker.InnerRun (System.Object state) [0x00000] at Mono.WebServer.ModMonoWorker.Run (System.Object state) [0x00000] [Tue Apr 20 03:10:26 2010] [error] (70014)End of file found: read_data failed [Tue Apr 20 03:10:26 2010] [error] Command stream corrupted, last command was -1 Along with the above errors, Apache's error.log is packed with hundreds (if not thousands) of the following error: Maximum number (20) of concurrent mod_mono requests to /tmp/mod_mono_dashboard_default_2.lock reached. Droping request. At the moment, I'm thinking there might be something wrong with configuration here (it's basically running on out-of-the-box config)

    Read the article

  • Building Dynamic Classes in Objective C

    - by kjell_
    I'm a somewhat competent ruby programmer. Yesterday I decided to finally try my hand with Apple's Cocoa frameworks. Help me see things the ObjC way? I'm trying to get my head around objc_allocateClassPair and objc_registerClassPair. My goal is to dynamically generate a few classes and then be able to use them as I would any other class. Does this work in Obj C? Having allocated and registered class A, I get a compile error when calling [[A alloc] init]; (it says 'A' Undeclared). I can only instantiate A using runtime's objc_getClass method. Is there any way to tell the compiler about A and pass it messages like I would NSString? A compiler flag or something? I have 10 or so other classes (B, C, …), all with the same superclass. I want to message them directly in code ([A classMethod], [B classMethod], …) without needing objc_getClass. Am I trying to be too dynamic here or just botching my implementation? It looks something like this… NSString *name = @"test"; Class newClass = objc_allocateClassPair([NSString class], [name UTF8String], 0); objc_registerClassPair(newClass); id a = [[objc_getClass("A") alloc] init]; NSLog(@"new class: %@ superclass: %@", a, [a superclass]); //[[A alloc] init]; blows up.

    Read the article

  • Python Pre-testing for exceptions when coverage fails

    - by Tal Weiss
    I recently came across a simple but nasty bug. I had a list and I wanted to find the smallest member in it. I used Python's built-in min(). Everything worked great until in some strange scenario the list was empty (due to strange user input I could not have anticipated). My application crashed with a ValueError (BTW - not documented in the official docs). I have very extensive unit tests and I regularly check coverage to avoid surprises like this. I also use Pylint (everything is integrated in PyDev) and I never ignore warnings, yet I failed to catch this bug before my users did. Is there anything I can change in my methodology to avoid these kind of runtime errors? (which would have been caught at compile time in Java / C#?). I'm looking for something more than wrapping my code with a big try-except. What else can I do? How many other build in Python functions are hiding nasty surprises like this???

    Read the article

  • convincing C# compiler that execution will stop after a member returns

    - by Sarah Vessels
    I don't think this is currently possible or if it's even a good idea, but it's something I was thinking about just now. I use MSTest for unit testing my C# project. In one of my tests, I do the following: MyClass instance; try { instance = getValue(); } catch (MyException ex) { Assert.Fail("Caught MyException"); } instance.doStuff(); // Use of unassigned local variable 'instance' To make this code compile, I have to assign a value to instance either at its declaration or in the catch block. However, Assert.Fail will never, to the best of my knowledge, allow execution to proceed past it, hence instance will never be used without a value. Why is it then that I must assign a value to it? If I change the Assert.Fail to something like throw ex, the code compiles fine, I assume because it knows that exception will disallow execution to proceed to a point where instance would be used uninitialized. So is it a case of runtime versus compile-time knowledge about where execution will be allowed to proceed? Would it ever be reasonable for C# to have some way of saying that a member, in this case Assert.Fail, will never allow execution after it returns? Maybe that could be in the form of a method attribute. Would this be useful or an unnecessary complexity for the compiler?

    Read the article

  • Java Process.waitFor() and IO streams

    - by lynks
    I have the following code; String[] cmd = { "bash", "-c", "~/path/to/script.sh" }; Process p = Runtime.getRuntime().exec(cmd); PipeThread a = new PipeThread(p.getInputStream(), System.out); PipeThread b = new PipeThread(p.getErrorStream(), System.err); p.waitFor(); a.die(); b.die(); The PipeThread class is quite simple so I will include it in full; public class PipeThread implements Runnable { private BufferedInputStream in; private BufferedOutputStream out; public Thread thread; private boolean die = false; public PipeThread(InputStream i, OutputStream o) { in = new BufferedInputStream(i); out = new BufferedOutputStream(o); thread = new Thread(this); thread.start(); } public void die() { die = true; } public void run() { try { byte[] b = new byte[1024]; while(!die) { int x = in.read(b, 0, 1024); if(x > 0) out.write(b, 0, x); else die(); out.flush(); } } catch(Exception e) { e.printStackTrace(); } try { in.close(); out.close(); } catch(Exception e) { } } } My problem is this; p.waitFor() blocks endlessly, even after the subprocess has terminated. If I do not create the pair of PipeThread instances, then p.waitFor() works perfectly. What is it about the piping of io streams that is causing p.waitFor() to continue blocking? I'm confused as I thought the IO streams would be passive, unable to keep a process alive, or to make Java think the process is still alive.

    Read the article

  • C++ Exception Handling

    - by user1413793
    So I was writing some code and I noticed that apart from syntactical, type, and other compile-time errors, C++ does not throw any other exceptions. So I decided to test this out with a very trivial program: #include<iostream> int main() { std::count<<5/0<<std::endl; return 1 } When I compiled it using g++, g++ gave me a warning saying I was dividing by 0. But it still compiled the code. Then when I ran it, it printed some really large arbitrary number. When I want to know is, how does C++ deal with exceptions? Integer division by 0 should be a very trivial example of when an exception should be thrown and the program should terminate. Do I have to essentially enclose my entire program in a huge try block and then catch certain exceptions? I know in Python when an exception is thrown, the program will immediately terminate and print out the error. What does C++ do? Are there even runtime exceptions which stop execution and kill the program?

    Read the article

< Previous Page | 21 22 23 24 25 26 27 28 29 30 31 32  | Next Page >