How to throw an exception in ZSH - zsh

I am writing a function and I want to throw an exception when the input is invalid. When I googled I found that there is a throw MyException command but when I try to use it like this:
#! /usr/bin/zsh
throw Exception
The script throws the following error:
$ ./test.sh
./test.sh:2: command not found: throw
Is there an mechanism to throw error in ZSH? If so are there any resources?

throw and catch must be loaded first; they aren't built directly into the shell.
autoload throw catch
They are documented in zshcontrib(1), under EXCEPTION HANDLING, although it isn't immediately obvious that they need to be loaded.

Related

Flutter firebase - can't catch exception thrown white trying to update a document with a map with an empty key

While trying to update a document in Firestore with a map with an empty key (a bug in my code), I wasn't able to catch the exception, which resulted in an app crash.
Here's a sample code:
try {
Map<String, dynamic> crash = {"": 3}; // this is an empty key (bug)
await docRef.collection('collection').document('doc').updateData({"ABC": crash});
} catch (err) {
print(err);
}
The exception (quite reasonable):
*** Assertion failure in auto firebase::firestore::model::FieldPath::FromServerFormat(const absl::string_view)::(anonymous class)::operator()() const(), /project/ios/Pods/FirebaseFirestore/Firestore/core/src/firebase/firestore/model/field_path.cc:90
Lost connection to device.
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'FIRESTORE INTERNAL ASSERTION FAILED: Invalid field path (s3SEDn5nhnWiqeZjpDmY.``). Paths must not be empty, begin with '.', end with '.', or contain '..' (expected !segment.empty())'
I don't see the error printed to the console, nor I get to a breakpoint set there.
My questions / issues:
Am I using the try catch block in a wrong way? Why isn't the catch statement working?
After the app crashes, trying to relaunch it fails, with the following error:
FileSystemException: Getting current working directory failed, path = '' (OS Error: Too many open files in system, errno = 23)
Only uninstalling and reinstalling the app works.
Any idea if this is normal? If not, what can I do about it?
Crashes both on iOS and Android,
Firestore plugin version cloud_firestore: ^0.12.7
I had a similar issue trying to catch exeptions on updateData with a map with no internet connection (emulator).
await Firestore.instance.collection('collection').document(doc).updateDataa({"ABC": crash}).timeout(Duration(seconds: 10));
This was the only way i could handle the timeout and return connection error!

Acrobat AcroExch.App member not found error jscript ActiveXObject

I have a simple jscript program using Adobe Acrobat's Interapplication Communication API.
var AcroApp = new ActiveXObject("AcroExch.App");
AcroApp.Exit;
I receive the following error executing the second line:
Member not found. (Exception from HRESULT: 0x80020003 (DISP_E_MEMBERNOTFOUND))
When AcroApp is instantiated, it shows as an ActiveXObject. However, I'm stumped, any ideas?
Change:
AcroApp.Exit;
to
AcroApp.Exit();
Not sure why

Symfony2: __toString() must not throw an exception

I am deploying my Symfony2 application, but I am getting the following error:
FatalErrorException in classes.php line 0:
Error: Method Symfony\Component\HttpFoundation\Request::__toString() must not throw an exception
Apache is slightly more descriptive, stating something about Monolog:
PHP Fatal error: Method Symfony\\Component\\HttpFoundation\\Request::__toString() must not throw an exception in /my/path/vendor/monolog/monolog/src/Monolog/Formatter/NormalizerFormatter.php on line 0
It is also the only thing It is not clear to me how this is happening. Dev-environment on my local machine is running fine.
I have tried to clear the prod cache, the composer cache and restarted apache service. I also did a fresh "composer install" after clearing its cache.
Anyone has an idea how this can be solved? Am running Symfony v2.7.4.
You should to check your $_COOKIE or $_SESSION for example;
The trouble is you could have array value in $_COOKIE, so on your debug environment you could fall into the following situation:
Debug::enable() //see, i don't exclude E_NOTICE here
$request = Request::createFromGlobals();
echo $request->__toString();
//so, from now you've got your Exception because of
//Debug package converts E_NOTICE to Fatal
//which turns into Exception
So if you want to fix this trouble you need to:
find the real reason of exception triggering (notice, deprecated, strict message, etc)
exclude it from Debug: Debug::enable(~E_NOTICE);
OR just remove (string)$request from your code if possible;
see Request code:
//part of __toString() method
foreach ($this->cookies as $k => $v) {
$cookies[] = $k.'='.$v;
}

How to make SBT task fail and hence build itself?

I wrote a SBT task to run cssLint for my project using rhino. cssLint returns exit code to my SBT task.
My question is how to make the task fail if the exit code is non-zero?
I don't want to throw any exceptions. I want my last line of the task result to show [Failed] instead of [success] and exit code of my SBT task to be non-zero.
SAMPLE
MyTask {
val exitcode = //rhino functions
//what to do??
}
The actual intent is to fail the build if css errors are present.
The way of failing the build without producing the stacktrace on the console is using the exceptions that are specifically handled:
for sbt.MessageOnlyException an error message is logged twice (without task name and then with task name) and the build is stopped
mix in sbt.FeedbackProvidedException or sbt.UnprintableException to implement custom exceptions for which sbt does not print a stacktrace. The string with task name and exception's toString is logged on the top level once and the build is stopped. It is expected that essential information for the user is already logged before throwing these.
Disclaimer: I've not seen this information in sbt manual. Extracted from the sources of sbt 0.13.16. sbt.FeedbackProvidedException is used this way by sbt compiler, sbt tests and by sbt-web and Play sbt plugins.
My understanding is that the success message is printed out always unless
showSuccess setting is set to false or
a task throws an exception.
In your particular case you want to report an error and so you should throw an exception or a value of the type of the result that might be considered a sort of exception like None or Failure.
Say, you've got the following task defined in build.sbt:
lazy val tsk = taskKey[Unit]("Task that always fails")
tsk := {
throw new IllegalStateException("a message")
}
When you execute the tsk task, the exception is printed out with no [success] afterwards.
[no-success]> tsk
[trace] Stack trace suppressed: run last *:tsk for the full output.
[error] (*:tsk) java.lang.IllegalStateException: a message
[error] Total time: 0 s, completed Feb 15, 2014 11:45:27 PM
I would rather prefer avoiding this style of programming and rely on Option as a way to report an issue with processing.
With the following tskO definition:
lazy val tskO = taskKey[Option[String]]("Task that reports failure as None")
tskO := None
you'd then check the result and if it's None you'd know it's a failure.

Could not find a part of the path 'C:\Users\shyful\Desktop\MvcApp\MvcApp\Person\Upload\Jellyfish.jpg'

When i ran the Project ,it shows "Could not find a part of the path 'C:\Users\shyful\Desktop\MvcApp\MvcApp\Person\Upload\Jellyfish.jpg'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.DirectoryNotFoundException: Could not find a part of the path
'C:\Users\shyful\Desktop\MvcApp\MvcApp\Person\Upload\Jellyfish.jpg'.
uploadFile.SaveAs(filePatha);
db.image.Add(image);
db.Entry(image).State = EntityState.Modified;
where's wrong in my code
The exception message: "Could not find a part of the path ..." is the message of the DirectoryNotFoundException.
In order to save a file you have to ensure that the directory exists first!
Run this before you save the file:
if(!Directory.Exists(#"C:\Users\shyful\Desktop\MvcApp\MvcApp\Person\Upload\"))
{
Directory.CreateDirectory(#"C:\Users\shyful\Desktop\MvcApp\MvcApp\Person\Upload\");
}

Resources