Exception handling by using try and finally - apex

if i want Hndle exception in apex by using try and finally bock without catch block how can i do that?am trying to do through dev console bt its not handling exception throwing error

Related

Using msal_mobile with Flutter

When runing the MsalMobile example i have this error :
[ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: Instance of 'MsalMobileException'
Help me please
This question is incomplete. You need to identity the exact error causing the exception. Try catch will help you do that, check out the official docs for error handling here

Production Code's General try-catch Eats nUnit Assertion Exceptions Causing the Failing Tests to Pass

I understand that nUnit failed Assert statements throw an exception, and that's how Test runners detect an error has occurred. My problem is that there is a general try-catch block in the production code that eats these Assert exceptions, and the Unity Test runner thinks the code is running without any issue. I've simplified the code to this:
[UnityTest]
public IEnumerator End2EndTests_Test_Foo()
{
try
{
Assert.Fail("Something is wrong.");
}
catch (Exception)
{
UnityEngine.Debug.Log("* Something went wrong. I ate this exception! yum yum *");
}
yield break;
}
As I mentioned, this test passes in Unity Test Runner. What's the remedy?
Note 1: I have not put any assertion inside the production code. The assertions are in callbacks that are invoked by the production code. If any exception happens in the callbacks, the production code catches them. That's how the failed assertion exceptions are caught by production code, not the Test runner.
Note 2: Some background: The production code sends a request to a server. When it receives a response, it invokes all subscribers (=callbacks). My test code has subscribed to the OnResponse event. The failed assertion is inside that callback. The general try-catch is inside the production code, embracing the invocation of the OnResponse event.
Note 3: I don't want to put a special catch statement for nUnit in the production code and re-throw the exception. That's a bad solution because the production code should not have any dependency on a testing framework.
It's OK for your test to subscribe to the callbacks, but you can't assert in the method that the callback invokes. All you can do is record information.
The test itself, after installing the callback should wait for it to be callback to complete and then assert on the saved information.

Partition is below target replica or instance count

When attempting to publish a Service Fabric application to a local cluster, the cluster fails to load the application stating the error in the title. The stack trace points me to an exception line in OwinCommunicationListener.cs:
try
{
this.eventSource.LogInfo("Starting web server on " + this.listeningAddress);
this.webApp = WebApp.Start(this.listeningAddress, appBuilder => this.startup.Invoke(appBuilder));
this.eventSource.LogInfo("Listening on " + this.publishAddress);
return Task.FromResult(this.publishAddress);
}
catch (Exception ex)
{
var logString = $"Web server failed to open endpoint {endpointName}. {ex.ToString()}";
this.eventSource.LogFatal(logString);
this.StopWebServer();
throw ex; // points to this line from cluster manager
}
I am unable to inspect the exception thrown, but there is no useful exception information other than a TargetInvocationException with a stack trace to the line noted above. Why won't this application load on my local cluster?
It's hard to say without an actual exception message or stack trace but judging by the location from which the exception was thrown and the fact that the problem resolved itself the next morning, the most likely and most common cause of this is that the port you were trying to use to open the web listener was taken by some other process at the time, and the next morning the port was free again. This, by the way, isn't really specific to Service Fabric. You're just trying to open a socket on a port that was taken by someone else.
I'm honestly more curious about why you couldn't inspect the exception. I can think of three things off the top of my head to help with that:
Use "throw" instead of "throw ex" so you don't reset the stack trace.
Look at your logs. It looks like you're writing out an ETW event in your catch block. What did it say?
Use the Visual Studio debugger: Simply set a breakpoint in the catch block and start the application with debugging by pressing F5.

talend tFTPGet error can't find what the error string is

I am developing a talend job with tFTPGet to fetch a file.
When i try to run the job in to test out the code, a error is reported . How do i see what the exact error is to fix this?
You need to use the error message of the TFTPGet component in a user code component:
The code of TJava will be executed only if the TFTPGet failed, you can use this line of code:
System.out.println(((String)globalMap.get("tFTPGet_1_ERROR_MESSAGE")));
Then you will see the error message in your console.

how to use class to catch error in Log4net?

I use Log4net to catch errors. I want to create class and use it to catch errors. I don't want to catch error through TRY CATCH. How can I do it
Log4Net is supposed for logging facilities. And it could be used for logging exceptions.
But it cannot be used to catch exceptions.
If you want to log exceptions you need to use try catch then you can log caught exception via Log4Net.